]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Import.pm
lei: improve handling of Message-ID-less draft messages
[public-inbox.git] / lib / PublicInbox / Import.pm
index a070aa1e9be0f6969d09eb1111fd5494b8320b5b..46f57e27c2b452d13f31cb3a08111620bb1308a8 100644 (file)
@@ -21,8 +21,8 @@ use POSIX qw(strftime);
 
 sub default_branch () {
        state $default_branch = do {
-               delete local $ENV{GIT_CONFIG};
-               my $r = popen_rd([qw(git config --global init.defaultBranch)]);
+               my $r = popen_rd([qw(git config --global init.defaultBranch)],
+                                { GIT_CONFIG => undef });
                chomp(my $h = <$r> // '');
                close $r;
                $h eq '' ? 'refs/heads/master' : $h;
@@ -68,11 +68,9 @@ sub gfi_start {
                chomp($self->{tip} = $git->qx(qw(rev-parse --revs-only), $ref));
                die "fatal: rev-parse --revs-only $ref: \$?=$?" if $?;
                if ($self->{path_type} ne '2/38' && $self->{tip}) {
-                       local $/ = "\0";
-                       my @t = $git->qx(qw(ls-tree -r -z --name-only), $ref);
+                       my $t = $git->qx(qw(ls-tree -r -z --name-only), $ref);
                        die "fatal: ls-tree -r -z --name-only $ref: \$?=$?" if $?;
-                       chomp @t;
-                       $self->{-tree} = { map { $_ => 1 } @t };
+                       $self->{-tree} = { map { $_ => 1 } split(/\0/, $t) };
                }
                $in_r = $self->{in} = $git->popen(qw(fast-import
                                        --quiet --done --date-format=raw),
@@ -415,7 +413,19 @@ sub add {
                $smsg->{blob} = $self->get_mark(":$blob");
                $smsg->set_bytes($raw_email, $n);
                if (my $oidx = delete $smsg->{-oidx}) { # used by LeiStore
-                       return if $oidx->blob_exists($smsg->{blob});
+                       my @docids = $oidx->blob_exists($smsg->{blob});
+                       my @vivify_xvmd;
+                       for my $id (@docids) {
+                               if (my $cur = $oidx->get_art($id)) {
+                                       # already imported if bytes > 0
+                                       return if $cur->{bytes} > 0;
+                                       push @vivify_xvmd, $id;
+                               } else {
+                                       warn "W: $smsg->{blob} ",
+                                               "#$id gone (bug?)\n";
+                               }
+                       }
+                       $smsg->{-vivify_xvmd} = \@vivify_xvmd;
                }
        }
        my $ref = $self->{ref};
@@ -500,8 +510,8 @@ sub atfork_child {
        }
 }
 
-sub digest2mid ($$) {
-       my ($dig, $hdr) = @_;
+sub digest2mid ($$;$) {
+       my ($dig, $hdr, $fallback_time) = @_;
        my $b64 = $dig->clone->b64digest;
        # Make our own URLs nicer:
        # See "Base 64 Encoding with URL and Filename Safe Alphabet" in RFC4648
@@ -510,7 +520,7 @@ sub digest2mid ($$) {
        # Add a date prefix to prevent a leading '-' in case that trips
        # up some tools (e.g. if a Message-ID were a expected as a
        # command-line arg)
-       my $dt = msg_datestamp($hdr);
+       my $dt = msg_datestamp($hdr, $fallback_time);
        $dt = POSIX::strftime('%Y%m%d%H%M%S', gmtime($dt));
        "$dt.$b64" . '@z';
 }