]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/V2Writable.pm
doc: various overview-level module comments
[public-inbox.git] / lib / PublicInbox / V2Writable.pm
index 07319646b1c1efd6a955cde6ad549eab6db5357e..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";
 
@@ -230,6 +244,9 @@ sub idx_init {
 
        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);
        }
@@ -777,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";