]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiToMail.pm
lei index: new command to index mail w/o git storage
[public-inbox.git] / lib / PublicInbox / LeiToMail.pm
index 71acf952c046fc0c984b2205110723afba4df84f..da3a95d20d2e1869124f77d1e4b0f14b17d28ec6 100644 (file)
@@ -137,9 +137,15 @@ sub eml2mboxcl2 {
 
 sub git_to_mail { # git->cat_async callback
        my ($bref, $oid, $type, $size, $arg) = @_;
+       my ($write_cb, $smsg) = @$arg;
+       if ($type eq 'missing' && $smsg->{-lms_ro}) {
+               if ($bref = $smsg->{-lms_ro}->local_blob($oid, 1)) {
+                       $type = 'blob';
+                       $size = length($$bref);
+               }
+       }
        return warn("W: $oid is $type (!= blob)\n") if $type ne 'blob';
        return warn("E: $oid is empty\n") unless $size;
-       my ($write_cb, $smsg) = @$arg;
        die "BUG: expected=$smsg->{blob} got=$oid" if $smsg->{blob} ne $oid;
        $write_cb->($bref, $smsg);
 }
@@ -283,7 +289,8 @@ sub _maildir_write_cb ($$) {
                my ($bref, $smsg, $eml) = @_;
                $dst // return $lei->fail; # dst may be undef-ed in last run
                return if $dedupe && $dedupe->is_dup($eml //
-                                               PublicInbox::Eml->new($$bref));
+                                               PublicInbox::Eml->new($$bref),
+                                               $smsg);
                $lse->xsmsg_vmd($smsg) if $lse;
                my $n = _buf2maildir($dst, $bref // \($eml->as_string), $smsg);
                $sto->ipc_do('set_sync_info', $smsg->{blob}, $out, $n) if $sto;
@@ -305,7 +312,8 @@ sub _imap_write_cb ($$) {
                my ($bref, $smsg, $eml) = @_;
                $mic // return $lei->fail; # mic may be undef-ed in last run
                return if $dedupe && $dedupe->is_dup($eml //
-                                               PublicInbox::Eml->new($$bref));
+                                               PublicInbox::Eml->new($$bref),
+                                               $smsg);
                $lse->xsmsg_vmd($smsg) if $lse;
                my $uid = eval { $append->($mic, $folder, $bref, $smsg, $eml) };
                if (my $err = $@) {
@@ -642,6 +650,7 @@ sub ipc_atfork_child {
        my ($self) = @_;
        my $lei = $self->{lei};
        $lei->_lei_atfork_child;
+       $self->{-lms_ro} = $lei->{lse}->lms if $lei->{lse};
        $lei->{auth}->do_auth_atfork($self) if $lei->{auth};
        $SIG{__WARN__} = PublicInbox::Eml::warn_ignore_cb();
        $self->SUPER::ipc_atfork_child;
@@ -663,6 +672,7 @@ sub poke_dst {
 sub write_mail { # via ->wq_io_do
        my ($self, $smsg, $eml) = @_;
        return $self->{wcb}->(undef, $smsg, $eml) if $eml;
+       $smsg->{-lms_ro} = $self->{-lms_ro};
        $self->{lei}->{ale}->git->cat_async($smsg->{blob}, \&git_to_mail,
                                [$self->{wcb}, $smsg]);
 }