1 # Copyright (C) 2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # This interface wraps and mimics PublicInbox::Import
5 package PublicInbox::V2Writable;
8 use base qw(PublicInbox::Lock);
9 use PublicInbox::SearchIdxPart;
10 use PublicInbox::MIME;
12 use PublicInbox::Import;
13 use PublicInbox::MID qw(mids);
14 use PublicInbox::ContentId qw(content_id content_digest);
15 use PublicInbox::Inbox;
16 use PublicInbox::OverIdx;
17 use PublicInbox::Msgmap;
18 use PublicInbox::Spawn;
21 # an estimate of the post-packed size to the raw uncompressed size
22 my $PACKING_FACTOR = 0.4;
24 # assume 2 cores if GNU nproc(1) is not available
26 int($ENV{NPROC} || `nproc 2>/dev/null` || 2);
29 sub count_partitions ($) {
32 my $xpfx = $self->{xpfx};
34 # always load existing partitions in case core count changes:
35 # Also, partition count may change while -watch is running
38 foreach my $part (<$xpfx/*>) {
39 -d $part && $part =~ m!/\d+\z! or next;
41 Search::Xapian::Database->new($part)->close;
50 my ($class, $v2ibx, $creat) = @_;
51 my $dir = $v2ibx->{mainrepo} or die "no mainrepo in inbox\n";
55 File::Path::mkpath($dir);
57 die "$dir does not exist\n";
61 $v2ibx = PublicInbox::InboxWritable->new($v2ibx);
63 my $xpfx = "$dir/xap" . PublicInbox::Search::SCHEMA_VERSION;
66 im => undef, # PublicInbox::Import
70 over => PublicInbox::OverIdx->new("$xpfx/over.sqlite3", 1),
71 lock_path => "$dir/inbox.lock",
72 # limit each git repo (epoch) to 1GB or so
73 rotate_bytes => int((1024 * 1024 * 1024) / $PACKING_FACTOR),
74 last_commit => [], # git repo -> commit
76 $self->{partitions} = count_partitions($self) || nproc();
81 my ($self, $parallel) = @_;
82 $self->{parallel} = $parallel;
85 git_dir_latest($self, \$epoch_max);
86 $self->git_init($epoch_max >= 0 ? $epoch_max : 0);
90 # returns undef on duplicate or spam
91 # mimics Import::add and wraps it for v2
93 my ($self, $mime, $check_cb) = @_;
97 $mime = $check_cb->($mime) or return;
100 # All pipes (> $^F) known to Perl 5.6+ have FD_CLOEXEC set,
101 # as does SQLite 3.4.1+ (released in 2007-07-20), and
102 # Xapian 1.3.2+ (released 2015-03-15).
103 # For the most part, we can spawn git-fast-import without
104 # leaking FDs to it...
108 my $num = num_for($self, $mime, \$mid0);
109 defined $num or return; # duplicate
110 defined $mid0 or die "BUG: $mid0 undefined\n";
111 my $im = $self->importer;
112 my $cmt = $im->add($mime);
113 $cmt = $im->get_mark($cmt);
114 $self->{last_commit}->[$self->{epoch_max}] = $cmt;
116 my ($oid, $len, $msgref) = @{$im->{last_object}};
117 $self->{over}->add_overview($mime, $len, $num, $oid, $mid0);
118 my $nparts = $self->{partitions};
119 my $part = $num % $nparts;
120 my $idx = $self->idx_part($part);
121 $idx->index_raw($len, $msgref, $num, $oid, $mid0, $mime);
122 my $n = $self->{transact_bytes} += $len;
123 if ($n > (PublicInbox::SearchIdx::BATCH_BYTES * $nparts)) {
131 my ($self, $mime, $mid0) = @_;
132 my $mids = mids($mime->header_obj);
134 my $mid = $mids->[0];
135 my $num = $self->{mm}->mid_insert($mid);
136 if (defined $num) { # common case
141 # crap, Message-ID is already known, hope somebody just resent:
142 foreach my $m (@$mids) {
143 # read-only lookup now safe to do after above barrier
144 my $existing = $self->lookup_content($mime, $m);
145 # easy, don't store duplicates
146 # note: do not add more diagnostic info here since
147 # it gets noisy on public-inbox-watch restarts
152 warn "<$mid> reused for mismatched content\n";
154 # try the rest of the mids
155 for(my $i = $#$mids; $i >= 1; $i--) {
157 $num = $self->{mm}->mid_insert($m);
159 warn "alternative <$m> for <$mid> found\n";
165 # none of the existing Message-IDs are good, generate a new one:
166 num_for_harder($self, $mime, $mid0);
170 my ($self, $mime, $mid0) = @_;
172 my $hdr = $mime->header_obj;
173 my $dig = content_digest($mime);
174 $$mid0 = PublicInbox::Import::digest2mid($dig);
175 my $num = $self->{mm}->mid_insert($$mid0);
176 unless (defined $num) {
177 # it's hard to spoof the last Received: header
178 my @recvd = $hdr->header_raw('Received');
179 $dig->add("Received: $_") foreach (@recvd);
180 $$mid0 = PublicInbox::Import::digest2mid($dig);
181 $num = $self->{mm}->mid_insert($$mid0);
183 # fall back to a random Message-ID and give up determinism:
184 until (defined($num)) {
186 $$mid0 = PublicInbox::Import::digest2mid($dig);
187 warn "using random Message-ID <$$mid0> as fallback\n";
188 $num = $self->{mm}->mid_insert($$mid0);
191 PublicInbox::Import::append_mid($hdr, $$mid0);
196 my ($self, $part) = @_;
197 $self->{idx_parts}->[$part];
203 return if $self->{idx_parts};
204 my $ibx = $self->{-inbox};
206 # do not leak read-only FDs to child processes, we only have these
207 # FDs for duplicate detection so they should not be
208 # frequently activated.
209 delete $ibx->{$_} foreach (qw(git mm search));
211 if ($self->{parallel}) {
212 pipe(my ($r, $w)) or die "pipe failed: $!";
213 $self->{bnote} = [ $r, $w ];
217 my $over = $self->{over};
219 $ibx->with_umask(sub {
223 # -compact can change partition count while -watch is idle
224 my $nparts = count_partitions($self);
225 if ($nparts && $nparts != $self->{partitions}) {
226 $self->{partitions} = $nparts;
229 # need to create all parts before initializing msgmap FD
230 my $max = $self->{partitions} - 1;
232 # idx_parts must be visible to all forked processes
233 my $idx = $self->{idx_parts} = [];
234 for my $i (0..$max) {
235 push @$idx, PublicInbox::SearchIdxPart->new($self, $i);
238 # Now that all subprocesses are up, we can open the FDs
240 my $mm = $self->{mm} = PublicInbox::Msgmap->new_file(
241 "$self->{-inbox}->{mainrepo}/msgmap.sqlite3", 1);
242 $mm->{dbh}->begin_work;
247 my ($self, $purge) = @_; # $purge = { $object_id => 1, ... }
249 my $pfx = "$self->{-inbox}->{mainrepo}/git";
251 foreach my $i (0..$self->{epoch_max}) {
252 my $git = PublicInbox::Git->new("$pfx/$i.git");
253 my $im = $self->import_init($git, 0, 1);
254 $purges->[$i] = $im->purge_oids($purge);
259 sub remove_internal {
260 my ($self, $mime, $cmt_msg, $purge) = @_;
262 my $im = $self->importer unless $purge;
263 my $over = $self->{over};
264 my $cid = content_id($mime);
265 my $parts = $self->{idx_parts};
266 my $mm = $self->{mm};
268 my $mids = mids($mime->header_obj);
270 # We avoid introducing new blobs into git since the raw content
271 # can be slightly different, so we do not need the user-supplied
272 # message now that we have the mids and content_id
276 foreach my $mid (@$mids) {
279 while (my $smsg = $over->next_by_mid($mid, \$id, \$prev)) {
280 my $msg = get_blob($self, $smsg);
281 if (!defined($msg)) {
282 warn "broken smsg for $mid\n";
286 my $cur = PublicInbox::MIME->new($msg);
287 if (content_id($cur) eq $cid) {
288 $smsg->{mime} = $cur;
289 $gone{$smsg->{num}} = [ $smsg, \$orig ];
292 my $n = scalar keys %gone;
295 warn "BUG: multiple articles linked to <$mid>\n",
296 join(',', sort keys %gone), "\n";
298 foreach my $num (keys %gone) {
299 my ($smsg, $orig) = @{$gone{$num}};
300 $mm->num_delete($num);
301 # $removed should only be set once assuming
302 # no bugs in our deduplication code:
304 my $oid = $smsg->{blob};
308 ($mark, undef) = $im->remove($orig, $cmt_msg);
311 $self->unindex_oid_remote($oid, $mid);
316 my $cmt = $im->get_mark($mark);
317 $self->{last_commit}->[$self->{epoch_max}] = $cmt;
319 if ($purge && scalar keys %$purge) {
320 return purge_oids($self, $purge);
326 my ($self, $mime, $cmt_msg) = @_;
327 remove_internal($self, $mime, $cmt_msg);
331 my ($self, $mime) = @_;
332 my $purges = remove_internal($self, $mime, undef, {});
333 $self->idx_init if @$purges; # ->done is called on purges
334 for my $i (0..$#$purges) {
335 defined(my $cmt = $purges->[$i]) or next;
336 $self->{last_commit}->[$i] = $cmt;
341 sub last_commit_part ($$;$) {
342 my ($self, $i, $cmt) = @_;
343 my $v = PublicInbox::Search::SCHEMA_VERSION();
344 $self->{mm}->last_commit_xap($v, $i, $cmt);
347 sub set_last_commits ($) {
349 defined(my $epoch_max = $self->{epoch_max}) or return;
350 my $last_commit = $self->{last_commit};
351 foreach my $i (0..$epoch_max) {
352 defined(my $cmt = $last_commit->[$i]) or next;
353 $last_commit->[$i] = undef;
354 last_commit_part($self, $i, $cmt);
360 $self->{bnote} or return;
362 my $barrier = { map { $_ => 1 } (0..$n) };
366 my ($self, $barrier) = @_;
367 my $bnote = $self->{bnote} or return;
369 while (scalar keys %$barrier) {
370 defined(my $l = $r->getline) or die "EOF on barrier_wait: $!";
371 $l =~ /\Abarrier (\d+)/ or die "bad line on barrier_wait: $l";
372 delete $barrier->{$1} or die "bad part[$1] on barrier wait";
376 sub checkpoint ($;$) {
377 my ($self, $wait) = @_;
379 if (my $im = $self->{im}) {
386 my $parts = $self->{idx_parts};
388 my $dbh = $self->{mm}->{dbh};
390 # SQLite msgmap data is second in importance
393 # SQLite overview is third
394 $self->{over}->commit_lazy;
396 # Now deal with Xapian
398 my $barrier = $self->barrier_init(scalar @$parts);
400 # each partition needs to issue a barrier command
401 $_->remote_barrier for @$parts;
403 # wait for each Xapian partition
404 $self->barrier_wait($barrier);
406 $_->remote_commit for @$parts;
409 # last_commit is special, don't commit these until
410 # remote partitions are done:
412 set_last_commits($self);
417 $self->{transact_bytes} = 0;
420 # issue a write barrier to ensure all data is visible to other processes
421 # and read-only ops. Order of data importance is: git > SQLite > Xapian
422 sub barrier { checkpoint($_[0], 1) };
426 my $im = delete $self->{im};
427 $im->done if $im; # PublicInbox::Import::done
429 my $mm = delete $self->{mm};
430 $mm->{dbh}->commit if $mm;
431 my $parts = delete $self->{idx_parts};
433 $_->remote_close for @$parts;
435 $self->{over}->disconnect;
436 delete $self->{bnote};
437 $self->{transact_bytes} = 0;
438 $self->lock_release if $parts;
442 my ($self, $epoch) = @_;
443 my $pfx = "$self->{-inbox}->{mainrepo}/git";
444 my $git_dir = "$pfx/$epoch.git";
445 my @cmd = (qw(git init --bare -q), $git_dir);
446 PublicInbox::Import::run_die(\@cmd);
448 my $all = "$self->{-inbox}->{mainrepo}/all.git";
450 @cmd = (qw(git init --bare -q), $all);
451 PublicInbox::Import::run_die(\@cmd);
452 @cmd = (qw/git config/, "--file=$all/config",
453 'repack.writeBitmaps', 'true');
454 PublicInbox::Import::run_die(\@cmd);
457 @cmd = (qw/git config/, "--file=$git_dir/config",
458 'include.path', '../../all.git/config');
459 PublicInbox::Import::run_die(\@cmd);
461 my $alt = "$all/objects/info/alternates";
462 my $new_obj_dir = "../../git/$epoch.git/objects";
465 open(my $fh, '<', $alt) or die "open < $alt: $!\n";
466 %alts = map { chomp; $_ => 1 } (<$fh>);
468 return $git_dir if $alts{$new_obj_dir};
469 open my $fh, '>>', $alt or die "open >> $alt: $!\n";
470 print $fh "$new_obj_dir\n" or die "print >> $alt: $!\n";
471 close $fh or die "close $alt: $!\n";
476 my ($self, $max) = @_;
478 my $pfx = "$self->{-inbox}->{mainrepo}/git";
479 return unless -d $pfx;
481 opendir my $dh, $pfx or die "opendir $pfx: $!\n";
482 while (defined(my $git_dir = readdir($dh))) {
483 $git_dir =~ m!\A(\d+)\.git\z! or next;
486 $latest = "$pfx/$git_dir";
494 my $im = $self->{im};
496 if ($im->{bytes_added} < $self->{rotate_bytes}) {
503 my $git_dir = $self->git_init(++$self->{epoch_max});
504 my $git = PublicInbox::Git->new($git_dir);
505 return $self->import_init($git, 0);
510 my $latest = git_dir_latest($self, \$max);
511 if (defined $latest) {
512 my $git = PublicInbox::Git->new($latest);
513 my $packed_bytes = $git->packed_bytes;
514 if ($packed_bytes >= $self->{rotate_bytes}) {
517 $self->{epoch_max} = $max;
518 return $self->import_init($git, $packed_bytes);
521 $self->{epoch_max} = $epoch;
522 $latest = $self->git_init($epoch);
523 $self->import_init(PublicInbox::Git->new($latest), 0);
527 my ($self, $git, $packed_bytes, $tmp) = @_;
528 my $im = PublicInbox::Import->new($git, undef, undef, $self->{-inbox});
529 $im->{bytes_added} = int($packed_bytes / $PACKING_FACTOR);
530 $im->{want_object_info} = 1;
531 $im->{lock_path} = undef;
532 $im->{path_type} = 'v2';
533 $self->{im} = $im unless $tmp;
539 my ($mid, $cur, $new) = @_;
540 use File::Temp qw(tempfile);
541 use PublicInbox::Spawn qw(spawn);
543 my ($ah, $an) = tempfile('email-cur-XXXXXXXX', TMPDIR => 1);
544 print $ah $cur->as_string or die "print: $!";
545 close $ah or die "close: $!";
546 my ($bh, $bn) = tempfile('email-new-XXXXXXXX', TMPDIR => 1);
547 PublicInbox::Import::drop_unwanted_headers($new);
548 print $bh $new->as_string or die "print: $!";
549 close $bh or die "close: $!";
550 my $cmd = [ qw(diff -u), $an, $bn ];
551 print STDERR "# MID conflict <$mid>\n";
552 my $pid = spawn($cmd, undef, { 1 => 2 });
553 defined $pid or die "diff failed to spawn $!";
554 waitpid($pid, 0) == $pid or die "diff did not finish";
559 my ($self, $smsg) = @_;
560 if (my $im = $self->{im}) {
561 my $msg = $im->cat_blob($smsg->{blob});
564 # older message, should be in alternates
565 my $ibx = $self->{-inbox};
566 $ibx->msg_by_smsg($smsg);
570 my ($self, $mime, $mid) = @_;
571 my $over = $self->{over};
572 my $cid = content_id($mime);
575 while (my $smsg = $over->next_by_mid($mid, \$id, \$prev)) {
576 my $msg = get_blob($self, $smsg);
577 if (!defined($msg)) {
578 warn "broken smsg for $mid\n";
581 my $cur = PublicInbox::MIME->new($msg);
582 if (content_id($cur) eq $cid) {
583 $smsg->{mime} = $cur;
588 # XXX DEBUG_DIFF is experimental and may be removed
589 diff($mid, $cur, $mime) if $ENV{DEBUG_DIFF};
596 my $fh = delete $self->{reindex_pipe};
598 if (my $parts = $self->{idx_parts}) {
599 $_->atfork_child foreach @$parts;
601 if (my $im = $self->{im}) {
604 die "unexpected mm" if $self->{mm};
605 close $self->{bnote}->[0] or die "close bnote[0]: $!\n";
610 my ($self, $D, $git, $oid) = @_;
611 my $msgref = $git->cat_file($oid);
612 my $mime = PublicInbox::MIME->new($$msgref);
613 my $mids = mids($mime->header_obj);
614 my $cid = content_id($mime);
615 foreach my $mid (@$mids) {
616 $D->{"$mid\0$cid"} = 1;
621 my ($self, $mm_tmp, $D, $git, $oid, $regen) = @_;
623 my $msgref = $git->cat_file($oid, \$len);
624 my $mime = PublicInbox::MIME->new($$msgref);
625 my $mids = mids($mime->header_obj);
626 my $cid = content_id($mime);
628 # get the NNTP article number we used before, highest number wins
629 # and gets deleted from mm_tmp;
633 foreach my $mid (@$mids) {
634 $del += (delete $D->{"$mid\0$cid"} || 0);
635 my $n = $mm_tmp->num_for($mid);
636 if (defined $n && $n > $num) {
641 if (!defined($mid0) && $regen && !$del) {
643 die "BUG: ran out of article numbers\n" if $num <= 0;
644 my $mm = $self->{mm};
645 foreach my $mid (reverse @$mids) {
646 if ($mm->mid_set($num, $mid) == 1) {
651 if (!defined($mid0)) {
652 my $id = '<' . join('> <', @$mids) . '>';
653 warn "Message-ID $id unusable for $num\n";
654 foreach my $mid (@$mids) {
655 defined(my $n = $mm->num_for($mid)) or next;
656 warn "#$n previously mapped for <$mid>\n";
661 if (!defined($mid0) || $del) {
662 if (!defined($mid0) && $del) { # expected for deletes
667 my $id = '<' . join('> <', @$mids) . '>';
669 warn "Skipping $id, no article number found\n";
670 if ($del && defined($mid0)) {
671 warn "$id was deleted $del " .
672 "time(s) but mapped to article #$num\n";
677 $mm_tmp->mid_delete($mid0) or
678 die "failed to delete <$mid0> for article #$num\n";
680 $self->{over}->add_overview($mime, $len, $num, $oid, $mid0);
681 my $nparts = $self->{partitions};
682 my $part = $num % $nparts;
683 my $idx = $self->idx_part($part);
684 $idx->index_raw($len, $msgref, $num, $oid, $mid0, $mime);
685 my $n = $self->{transact_bytes} += $len;
686 if ($n > (PublicInbox::SearchIdx::BATCH_BYTES * $nparts)) {
688 $mm_tmp->atfork_prepare;
689 $self->done; # release lock
690 # allow -watch or -mda to write...
691 $self->idx_init; # reacquire lock
692 $mm_tmp->atfork_parent;
696 # only update last_commit for $i on reindex iff newer than current
697 sub update_last_commit {
698 my ($self, $git, $i, $cmt) = @_;
699 my $last = last_commit_part($self, $i);
700 if (defined $last && is_ancestor($git, $last, $cmt)) {
701 my @cmd = (qw(rev-list --count), "$last..$cmt");
702 chomp(my $n = $git->qx(@cmd));
703 return if $n ne '' && $n == 0;
705 last_commit_part($self, $i, $cmt);
708 sub git_dir_n ($$) { "$_[0]->{-inbox}->{mainrepo}/git/$_[1].git" }
711 my ($self, $epoch_max) = @_;
713 for (my $i = $epoch_max; $i >= 0; $i--) {
714 $heads->[$i] = last_commit_part($self, $i);
719 sub is_ancestor ($$$) {
720 my ($git, $cur, $tip) = @_;
721 return 0 unless $git->check($cur);
722 my $cmd = [ 'git', "--git-dir=$git->{git_dir}",
723 qw(merge-base --is-ancestor), $cur, $tip ];
724 my $pid = spawn($cmd);
725 defined $pid or die "spawning ".join(' ', @$cmd)." failed: $!";
726 waitpid($pid, 0) == $pid or die join(' ', @$cmd) .' did not finish';
731 my ($self, $opts, $epoch_max, $ranges) = @_;
733 my $head = $self->{-inbox}->{ref_head} || 'refs/heads/master';
734 for (my $i = $epoch_max; $i >= 0; $i--) {
735 die "already indexing!\n" if $self->{index_pipe};
736 my $git_dir = git_dir_n($self, $i);
737 -d $git_dir or next; # missing parts are fine
738 my $git = PublicInbox::Git->new($git_dir);
739 chomp(my $tip = $git->qx('rev-parse', $head));
741 if (defined(my $cur = $ranges->[$i])) {
742 $range = "$cur..$tip";
743 if (is_ancestor($git, $cur, $tip)) { # common case
744 my $n = $git->qx(qw(rev-list --count), $range);
747 $ranges->[$i] = undef;
752 discontiguous range: $range
753 Rewritten history? (in $git_dir)
755 my $base = $git->qx('merge-base', $tip, $cur);
758 $range = "$base..$tip";
759 warn "found merge-base: $base\n"
763 discarding history at $cur
767 reindexing $git_dir starting at
770 $self->{"unindex-range.$i"} = "$base..$cur";
773 $range = $tip; # all of it
775 $ranges->[$i] = $range;
777 # can't use 'rev-list --count' if we use --diff-filter
778 my $fh = $git->popen(qw(log --pretty=tformat:%h
779 --no-notes --no-color --no-renames
780 --diff-filter=AM), $range, '--', 'm');
781 ++$regen_max while <$fh>;
786 sub unindex_oid_remote {
787 my ($self, $oid, $mid) = @_;
788 $_->remote_remove($oid, $mid) foreach @{$self->{idx_parts}};
789 $self->{over}->remove_oid($oid, $mid);
793 my ($self, $git, $oid) = @_;
794 my $msgref = $git->cat_file($oid);
795 my $mime = PublicInbox::MIME->new($msgref);
796 my $mids = mids($mime->header_obj);
797 $mime = $msgref = undef;
798 my $over = $self->{over};
799 foreach my $mid (@$mids) {
802 while (my $smsg = $over->next_by_mid($mid, \$id, \$prev)) {
803 $gone{$smsg->num} = 1 if $oid eq $smsg->{blob};
806 my $n = scalar keys %gone;
809 warn "BUG: multiple articles linked to $oid\n",
810 join(',',sort keys %gone), "\n";
812 $self->{unindexed}->{$_}++ foreach keys %gone;
813 $self->unindex_oid_remote($oid, $mid);
817 my $x40 = qr/[a-f0-9]{40}/;
819 my ($self, $opts, $git, $unindex_range) = @_;
820 my $un = $self->{unindexed} ||= {}; # num => removal count
821 my $before = scalar keys %$un;
822 my @cmd = qw(log --raw -r
823 --no-notes --no-color --no-abbrev --no-renames);
824 my $fh = $self->{reindex_pipe} = $git->popen(@cmd, $unindex_range);
826 /\A:\d{6} 100644 $x40 ($x40) [AM]\tm$/o or next;
827 $self->unindex_oid($git, $1);
829 delete $self->{reindex_pipe};
832 return unless $opts->{prune};
833 my $after = scalar keys %$un;
834 return if $before == $after;
836 # ensure any blob can not longer be accessed via dumb HTTP
837 PublicInbox::Import::run_die(['git', "--git-dir=$git->{git_dir}",
838 qw(-c gc.reflogExpire=now gc --prune=all)]);
842 my ($self, $opts) = @_;
845 my $latest = git_dir_latest($self, \$epoch_max);
846 return unless defined $latest;
847 $self->idx_init; # acquire lock
848 my $mm_tmp = $self->{mm}->tmp_clone;
849 my $ranges = $opts->{reindex} ? [] : $self->last_commits($epoch_max);
851 my ($min, $max) = $mm_tmp->minmax;
852 my $regen = $self->index_prepare($opts, $epoch_max, $ranges);
853 $$regen += $max if $max;
855 my @cmd = qw(log --raw -r --pretty=tformat:%h
856 --no-notes --no-color --no-abbrev --no-renames);
858 # work backwards through history
859 my $last_commit = [];
860 for (my $i = $epoch_max; $i >= 0; $i--) {
861 my $git_dir = git_dir_n($self, $i);
862 die "already reindexing!\n" if delete $self->{reindex_pipe};
863 -d $git_dir or next; # missing parts are fine
864 my $git = PublicInbox::Git->new($git_dir);
865 my $unindex = delete $self->{"unindex-range.$i"};
866 $self->unindex($opts, $git, $unindex) if $unindex;
867 defined(my $range = $ranges->[$i]) or next;
868 my $fh = $self->{reindex_pipe} = $git->popen(@cmd, $range);
871 if (/\A$x40$/o && !defined($cmt)) {
873 } elsif (/\A:\d{6} 100644 $x40 ($x40) [AM]\tm$/o) {
874 $self->reindex_oid($mm_tmp, $D, $git, $1,
876 } elsif (/\A:\d{6} 100644 $x40 ($x40) [AM]\td$/o) {
877 $self->mark_deleted($D, $git, $1);
881 delete $self->{reindex_pipe};
882 $self->update_last_commit($git, $i, $cmt) if defined $cmt;
884 my @d = sort keys %$D;
886 warn "BUG: ", scalar(@d)," unseen deleted messages marked\n";
888 my ($mid, undef) = split(/\0/, $_, 2);