about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-01-31 22:28:13 -1000
committerEric Wong <e@80x24.org>2021-02-01 11:38:07 +0000
commit4e101abd56867b9f5286644d14ca05bcff49708c (patch)
treef427cb9b73945ca91e1bd178ca148eb45fb100c1
parente49cf9c629c0fd3024bdb63b5c5e84b590814c4e (diff)
downloadpublic-inbox-4e101abd56867b9f5286644d14ca05bcff49708c.tar.gz
This fixes "--dedupe none" with Maildir where we don't
create the object at all.
-rw-r--r--lib/PublicInbox/LeiDedupe.pm4
-rw-r--r--lib/PublicInbox/LeiOverview.pm18
-rw-r--r--lib/PublicInbox/LeiToMail.pm3
3 files changed, 13 insertions, 12 deletions
diff --git a/lib/PublicInbox/LeiDedupe.pm b/lib/PublicInbox/LeiDedupe.pm
index 3f478aa4..e3ae8e33 100644
--- a/lib/PublicInbox/LeiDedupe.pm
+++ b/lib/PublicInbox/LeiDedupe.pm
@@ -103,8 +103,8 @@ sub new {
         bless [ $skv, undef, undef, $m ], $cls;
 }
 
-# returns true on unseen messages according to the deduplication strategy,
-# returns false if seen
+# returns true on seen messages according to the deduplication strategy,
+# returns false if unseen
 sub is_dup {
         my ($self, $eml, $oid) = @_;
         !$self->[1]->($eml, $oid);
diff --git a/lib/PublicInbox/LeiOverview.pm b/lib/PublicInbox/LeiOverview.pm
index c67e2747..fa041457 100644
--- a/lib/PublicInbox/LeiOverview.pm
+++ b/lib/PublicInbox/LeiOverview.pm
@@ -92,13 +92,14 @@ sub new {
                         ovv_out_lk_init($self);
                 }
         }
-        if (!$json) {
+        if ($json) {
+                $lei->{dedupe} //= PublicInbox::LeiDedupe->new($lei);
+        } else {
                 # default to the cheapest sort since MUA usually resorts
                 $lei->{opt}->{'sort'} //= 'docid' if $dst ne '/dev/stdout';
                 $lei->{l2m} = eval { PublicInbox::LeiToMail->new($lei) };
                 return $lei->fail($@) if $@;
         }
-        $lei->{dedupe} //= PublicInbox::LeiDedupe->new($lei);
         $self;
 }
 
@@ -201,15 +202,19 @@ sub _json_pretty {
 
 sub ovv_each_smsg_cb { # runs in wq worker usually
         my ($self, $lei, $ibxish) = @_;
-        my $json;
+        my ($json, $dedupe);
         $lei->{1}->autoflush(1);
-        my $dedupe = $lei->{dedupe} // die 'BUG: {dedupe} missing';
         if (my $pkg = $self->{json}) {
                 $json = $pkg->new;
                 $json->utf8->canonical;
                 $json->ascii(1) if $lei->{opt}->{ascii};
         }
-        my $l2m = $lei->{l2m} or $dedupe->prepare_dedupe;
+        my $l2m = $lei->{l2m};
+        if (!$l2m) {
+                $dedupe = $lei->{dedupe} // die 'BUG: {dedupe} missing';
+                $dedupe->prepare_dedupe;
+        }
+        $lei->{ovv_buf} = \(my $buf = '') if !$l2m;
         if ($l2m && !$ibxish) { # remote https?:// mboxrd
                 delete $l2m->{-wq_s1};
                 my $g2m = $l2m->can('git_to_mail');
@@ -241,7 +246,6 @@ sub ovv_each_smsg_cb { # runs in wq worker usually
                 my $git = $ibxish->git; # (LeiXSearch|Inbox|ExtSearch)->git
                 $self->{git} = $git; # for ovv_atexit_child
                 my $g2m = $l2m->can('git_to_mail');
-                $dedupe->prepare_dedupe;
                 sub {
                         my ($smsg, $mitem) = @_;
                         $smsg->{pct} = get_pct($mitem) if $mitem;
@@ -249,7 +253,6 @@ sub ovv_each_smsg_cb { # runs in wq worker usually
                 };
         } elsif ($self->{fmt} =~ /\A(concat)?json\z/ && $lei->{opt}->{pretty}) {
                 my $EOR = ($1//'') eq 'concat' ? "\n}" : "\n},";
-                $lei->{ovv_buf} = \(my $buf = '');
                 sub { # DIY prettiness :P
                         my ($smsg, $mitem) = @_;
                         return if $dedupe->is_smsg_dup($smsg);
@@ -273,7 +276,6 @@ sub ovv_each_smsg_cb { # runs in wq worker usually
                 }
         } elsif ($json) {
                 my $ORS = $self->{fmt} eq 'json' ? ",\n" : "\n"; # JSONL
-                $lei->{ovv_buf} = \(my $buf = '');
                 sub {
                         my ($smsg, $mitem) = @_;
                         return if $dedupe->is_smsg_dup($smsg);
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index 61b546b5..244bfb67 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -323,7 +323,7 @@ sub _buf2maildir {
 sub _maildir_write_cb ($$) {
         my ($self, $lei) = @_;
         my $dedupe = $lei->{dedupe};
-        $dedupe->prepare_dedupe;
+        $dedupe->prepare_dedupe if $dedupe;
         my $dst = $lei->{ovv}->{dst};
         sub { # for git_to_mail
                 my ($buf, $smsg, $eml) = @_;
@@ -464,7 +464,6 @@ sub write_mail { # via ->wq_do
         my $wcb = $self->{wcb} //= do { # first message
                 my %sig = $lei->atfork_child_wq($self);
                 @SIG{keys %sig} = values %sig; # not local
-                $lei->{dedupe}->prepare_dedupe;
                 $self->write_cb($lei);
         };
         my $git = $self->{"$$\0$git_dir"} //= PublicInbox::Git->new($git_dir);