]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/V2Writable.pm
Merge commit 'mem'
[public-inbox.git] / lib / PublicInbox / V2Writable.pm
index 152d90ab3ea595fd56c8b7643831fd28fbecbdbb..222df5c2ffa6d0cf3dae884ea734ee9973dc1619 100644 (file)
@@ -2,6 +2,7 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # This interface wraps and mimics PublicInbox::Import
+# Used to write to V2 inboxes (see L<public-inbox-v2-format(5)>).
 package PublicInbox::V2Writable;
 use strict;
 use warnings;
@@ -163,6 +164,19 @@ sub num_for {
                        return if $existing;
                }
 
+               # AltId may pre-populate article numbers (e.g. X-Mail-Count
+               # or NNTP article number), use that article number if it's
+               # not in Over.
+               my $altid = $self->{-inbox}->{altid};
+               if ($altid && grep(/:file=msgmap\.sqlite3\z/, @$altid)) {
+                       my $num = $self->{mm}->num_for($mid);
+
+                       if (defined $num && !$self->{over}->get_art($num)) {
+                               $$mid0 = $mid;
+                               return $num;
+                       }
+               }
+
                # very unlikely:
                warn "<$mid> reused for mismatched content\n";
 
@@ -223,11 +237,19 @@ sub idx_init {
        # frequently activated.
        delete $ibx->{$_} foreach (qw(git mm search));
 
-       if ($self->{parallel}) {
-               pipe(my ($r, $w)) or die "pipe failed: $!";
-               $self->{bnote} = [ $r, $w ];
-               $w->autoflush(1);
-       }
+       my $indexlevel = $ibx->{indexlevel};
+       if ($indexlevel && $indexlevel eq 'basic') {
+               $self->{parallel} = 0;
+       }
+
+       if ($self->{parallel}) {
+               pipe(my ($r, $w)) or die "pipe failed: $!";
+               # pipe for barrier notifications doesn't need to be big,
+               # 1031: F_SETPIPE_SZ
+               fcntl($w, 1031, 4096) if $^O eq 'linux';
+               $self->{bnote} = [ $r, $w ];
+               $w->autoflush(1);
+       }
 
        my $over = $self->{over};
        $ibx->umask_prepare;
@@ -772,7 +794,8 @@ sub index_prepare {
                my $git_dir = git_dir_n($self, $i);
                -d $git_dir or next; # missing parts are fine
                my $git = PublicInbox::Git->new($git_dir);
-               chomp(my $tip = $git->qx('rev-parse', $head));
+               chomp(my $tip = $git->qx(qw(rev-parse -q --verify), $head));
+               next if $?; # new repo
                my $range;
                if (defined(my $cur = $ranges->[$i])) {
                        $range = "$cur..$tip";