]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/V2Writable.pm
replace Xapian skeleton with SQLite overview DB
[public-inbox.git] / lib / PublicInbox / V2Writable.pm
1 # Copyright (C) 2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # This interface wraps and mimics PublicInbox::Import
5 package PublicInbox::V2Writable;
6 use strict;
7 use warnings;
8 use base qw(PublicInbox::Lock);
9 use PublicInbox::SearchIdxPart;
10 use PublicInbox::MIME;
11 use PublicInbox::Git;
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::OverIdxFork;
17 use PublicInbox::Msgmap;
18 use IO::Handle;
19
20 # an estimate of the post-packed size to the raw uncompressed size
21 my $PACKING_FACTOR = 0.4;
22
23 # assume 2 cores if GNU nproc(1) is not available
24 sub nproc () {
25         int($ENV{NPROC} || `nproc 2>/dev/null` || 2);
26 }
27
28 sub new {
29         my ($class, $v2ibx, $creat) = @_;
30         my $dir = $v2ibx->{mainrepo} or die "no mainrepo in inbox\n";
31         unless (-d $dir) {
32                 if ($creat) {
33                         require File::Path;
34                         File::Path::mkpath($dir);
35                 } else {
36                         die "$dir does not exist\n";
37                 }
38         }
39
40         my $nparts = 0;
41         my $xpfx = "$dir/xap" . PublicInbox::Search::SCHEMA_VERSION;
42
43         # always load existing partitions in case core count changes:
44         if (-d $xpfx) {
45                 foreach my $part (<$xpfx/*>) {
46                         -d $part && $part =~ m!/\d+\z! or next;
47                         eval {
48                                 Search::Xapian::Database->new($part)->close;
49                                 $nparts++;
50                         };
51                 }
52         }
53         $nparts = nproc() if ($nparts == 0);
54
55         $v2ibx = PublicInbox::InboxWritable->new($v2ibx);
56         my $self = {
57                 -inbox => $v2ibx,
58                 im => undef, #  PublicInbox::Import
59                 partitions => $nparts,
60                 parallel => 1,
61                 transact_bytes => 0,
62                 over => PublicInbox::OverIdxFork->new("$xpfx/over.sqlite3"),
63                 lock_path => "$dir/inbox.lock",
64                 # limit each repo to 1GB or so
65                 rotate_bytes => int((1024 * 1024 * 1024) / $PACKING_FACTOR),
66         };
67         bless $self, $class;
68 }
69
70 sub init_inbox {
71         my ($self, $parallel) = @_;
72         $self->{parallel} = $parallel;
73         $self->idx_init;
74         my $max_git = -1;
75         git_dir_latest($self, \$max_git);
76         $self->git_init($max_git >= 0 ? $max_git : 0);
77         $self->done;
78 }
79
80 # returns undef on duplicate or spam
81 # mimics Import::add and wraps it for v2
82 sub add {
83         my ($self, $mime, $check_cb) = @_;
84
85         # spam check:
86         if ($check_cb) {
87                 $mime = $check_cb->($mime) or return;
88         }
89
90         # All pipes (> $^F) known to Perl 5.6+ have FD_CLOEXEC set,
91         # as does SQLite 3.4.1+ (released in 2007-07-20), and
92         # Xapian 1.3.2+ (released 2015-03-15).
93         # For the most part, we can spawn git-fast-import without
94         # leaking FDs to it...
95         $self->idx_init;
96
97         my $mid0;
98         my $num = num_for($self, $mime, \$mid0);
99         defined $num or return; # duplicate
100         defined $mid0 or die "BUG: $mid0 undefined\n";
101         my $im = $self->importer;
102         my $cmt = $im->add($mime);
103         $cmt = $im->get_mark($cmt);
104         my ($oid, $len, $msgref) = @{$im->{last_object}};
105
106         my $nparts = $self->{partitions};
107         my $part = $num % $nparts;
108         my $idx = $self->idx_part($part);
109         $idx->index_raw($len, $msgref, $num, $oid, $mid0, $mime);
110         my $n = $self->{transact_bytes} += $len;
111         if ($n > (PublicInbox::SearchIdx::BATCH_BYTES * $nparts)) {
112                 $self->checkpoint;
113         }
114
115         $mime;
116 }
117
118 sub num_for {
119         my ($self, $mime, $mid0) = @_;
120         my $mids = mids($mime->header_obj);
121         if (@$mids) {
122                 my $mid = $mids->[0];
123                 my $num = $self->{mm}->mid_insert($mid);
124                 if (defined $num) { # common case
125                         $$mid0 = $mid;
126                         return $num;
127                 };
128
129                 # crap, Message-ID is already known, hope somebody just resent:
130                 $self->barrier;
131                 foreach my $m (@$mids) {
132                         # read-only lookup now safe to do after above barrier
133                         my $existing = $self->lookup_content($mime, $m);
134                         # easy, don't store duplicates
135                         # note: do not add more diagnostic info here since
136                         # it gets noisy on public-inbox-watch restarts
137                         return if $existing;
138                 }
139
140                 # very unlikely:
141                 warn "<$mid> reused for mismatched content\n";
142
143                 # try the rest of the mids
144                 for(my $i = $#$mids; $i >= 1; $i--) {
145                         my $m = $mids->[$i];
146                         $num = $self->{mm}->mid_insert($m);
147                         if (defined $num) {
148                                 warn "alternative <$m> for <$mid> found\n";
149                                 $$mid0 = $m;
150                                 return $num;
151                         }
152                 }
153         }
154         # none of the existing Message-IDs are good, generate a new one:
155         num_for_harder($self, $mime, $mid0);
156 }
157
158 sub num_for_harder {
159         my ($self, $mime, $mid0) = @_;
160
161         my $hdr = $mime->header_obj;
162         my $dig = content_digest($mime);
163         $$mid0 = PublicInbox::Import::digest2mid($dig);
164         my $num = $self->{mm}->mid_insert($$mid0);
165         unless (defined $num) {
166                 # it's hard to spoof the last Received: header
167                 my @recvd = $hdr->header_raw('Received');
168                 $dig->add("Received: $_") foreach (@recvd);
169                 $$mid0 = PublicInbox::Import::digest2mid($dig);
170                 $num = $self->{mm}->mid_insert($$mid0);
171
172                 # fall back to a random Message-ID and give up determinism:
173                 until (defined($num)) {
174                         $dig->add(rand);
175                         $$mid0 = PublicInbox::Import::digest2mid($dig);
176                         warn "using random Message-ID <$$mid0> as fallback\n";
177                         $num = $self->{mm}->mid_insert($$mid0);
178                 }
179         }
180         PublicInbox::Import::append_mid($hdr, $$mid0);
181         $num;
182 }
183
184 sub idx_part {
185         my ($self, $part) = @_;
186         $self->{idx_parts}->[$part];
187 }
188
189 # idempotent
190 sub idx_init {
191         my ($self) = @_;
192         return if $self->{idx_parts};
193         my $ibx = $self->{-inbox};
194
195         # do not leak read-only FDs to child processes, we only have these
196         # FDs for duplicate detection so they should not be
197         # frequently activated.
198         delete $ibx->{$_} foreach (qw(git mm search));
199
200         my $over = $self->{over};
201         $ibx->umask_prepare;
202         $ibx->with_umask(sub {
203                 $self->lock_acquire;
204                 $over->create($self);
205
206                 # need to create all parts before initializing msgmap FD
207                 my $max = $self->{partitions} - 1;
208
209                 # idx_parts must be visible to all forked processes
210                 my $idx = $self->{idx_parts} = [];
211                 for my $i (0..$max) {
212                         push @$idx, PublicInbox::SearchIdxPart->new($self, $i);
213                 }
214
215                 # Now that all subprocesses are up, we can open the FDs
216                 # for SQLite:
217                 my $mm = $self->{mm} = PublicInbox::Msgmap->new_file(
218                         "$self->{-inbox}->{mainrepo}/msgmap.sqlite3", 1);
219                 $mm->{dbh}->begin_work;
220         });
221 }
222
223 sub purge_oids {
224         my ($self, $purge) = @_; # $purge = { $object_id => 1, ... }
225         $self->done;
226         my $pfx = "$self->{-inbox}->{mainrepo}/git";
227         foreach my $i (0..$self->{max_git}) {
228                 my $git = PublicInbox::Git->new("$pfx/$i.git");
229                 my $im = $self->import_init($git, 0);
230                 $im->purge_oids($purge);
231         }
232 }
233
234 sub remove_internal {
235         my ($self, $mime, $cmt_msg, $purge) = @_;
236         $self->barrier;
237         $self->idx_init;
238         my $im = $self->importer unless $purge;
239         my $ibx = $self->{-inbox};
240         my $srch = $ibx->search;
241         my $cid = content_id($mime);
242         my $parts = $self->{idx_parts};
243         my $mm = $self->{mm};
244         my $removed;
245         my $mids = mids($mime->header_obj);
246
247         # We avoid introducing new blobs into git since the raw content
248         # can be slightly different, so we do not need the user-supplied
249         # message now that we have the mids and content_id
250         $mime = undef;
251
252         foreach my $mid (@$mids) {
253                 $srch->reopen->each_smsg_by_mid($mid, sub {
254                         my ($smsg) = @_;
255                         $smsg->load_expand;
256                         my $msg = $ibx->msg_by_smsg($smsg);
257                         if (!defined($msg)) {
258                                 warn "broken smsg for $mid\n";
259                                 return 1; # continue
260                         }
261                         my $orig = $$msg;
262                         my $cur = PublicInbox::MIME->new($msg);
263                         if (content_id($cur) eq $cid) {
264                                 $mm->num_delete($smsg->num);
265                                 # $removed should only be set once assuming
266                                 # no bugs in our deduplication code:
267                                 $removed = $smsg;
268                                 $removed->{mime} = $cur;
269                                 my $oid = $smsg->{blob};
270                                 if ($purge) {
271                                         $purge->{$oid} = 1;
272                                 } else {
273                                         $im->remove(\$orig, $cmt_msg);
274                                 }
275                                 $orig = undef;
276                                 $removed->num; # memoize this for callers
277
278                                 foreach my $idx (@$parts) {
279                                         $idx->remote_remove($oid, $mid);
280                                 }
281                                 $self->{over}->remove_oid($oid, $mid);
282                         }
283                         1; # continue
284                 });
285                 $self->barrier;
286         }
287         if ($purge && scalar keys %$purge) {
288                 purge_oids($self, $purge);
289         }
290         $removed;
291 }
292
293 sub remove {
294         my ($self, $mime, $cmt_msg) = @_;
295         remove_internal($self, $mime, $cmt_msg);
296 }
297
298 sub purge {
299         my ($self, $mime) = @_;
300         remove_internal($self, $mime, undef, {});
301 }
302
303
304 sub done {
305         my ($self) = @_;
306         my $locked = defined $self->{idx_parts};
307         my $im = delete $self->{im};
308         $im->done if $im; # PublicInbox::Import::done
309         $self->searchidx_checkpoint(0);
310         $self->lock_release if $locked;
311 }
312
313 sub checkpoint {
314         my ($self) = @_;
315         my $im = $self->{im};
316         $im->checkpoint if $im; # PublicInbox::Import::checkpoint
317         $self->searchidx_checkpoint(1);
318 }
319
320 # issue a write barrier to ensure all data is visible to other processes
321 # and read-only ops.  Order of data importance is: git > SQLite > Xapian
322 sub barrier {
323         my ($self) = @_;
324
325         if (my $im = $self->{im}) {
326                 $im->barrier;
327         }
328         my $parts = $self->{idx_parts};
329         if ($parts) {
330                 my $dbh = $self->{mm}->{dbh};
331                 $dbh->commit; # SQLite msgmap data is second in importance
332
333                 my $over = $self->{over};
334
335                 # Now deal with Xapian and overview DB
336                 $over->barrier_init(scalar(@$parts));
337
338                 # each partition needs to issue a barrier command to over
339                 $_->remote_barrier foreach @$parts;
340
341                 $over->barrier_wait; # wait for each Xapian partition
342
343                 $dbh->begin_work;
344         }
345         $self->{transact_bytes} = 0;
346 }
347
348 sub searchidx_checkpoint {
349         my ($self, $more) = @_;
350
351         # order matters, we can only close {over} after all partitions
352         # are done because the partitions also write to {over}
353         if (my $parts = $self->{idx_parts}) {
354                 foreach my $idx (@$parts) {
355                         $idx->remote_commit; # propagates commit to over
356                         $idx->remote_close unless $more;
357                 }
358                 delete $self->{idx_parts} unless $more;
359         }
360
361         if (my $mm = $self->{mm}) {
362                 my $dbh = $mm->{dbh};
363                 $dbh->commit;
364                 if ($more) {
365                         $dbh->begin_work;
366                 } else {
367                         delete $self->{mm};
368                 }
369         }
370         my $over = $self->{over};
371         $over->remote_commit;
372         if (!$more) {
373                 $over->remote_close;
374         }
375         $self->{transact_bytes} = 0;
376 }
377
378 sub git_init {
379         my ($self, $new) = @_;
380         my $pfx = "$self->{-inbox}->{mainrepo}/git";
381         my $git_dir = "$pfx/$new.git";
382         my @cmd = (qw(git init --bare -q), $git_dir);
383         PublicInbox::Import::run_die(\@cmd);
384
385         my $all = "$self->{-inbox}->{mainrepo}/all.git";
386         unless (-d $all) {
387                 @cmd = (qw(git init --bare -q), $all);
388                 PublicInbox::Import::run_die(\@cmd);
389                 @cmd = (qw/git config/, "--file=$all/config",
390                                 'repack.writeBitmaps', 'true');
391                 PublicInbox::Import::run_die(\@cmd);
392         }
393
394         @cmd = (qw/git config/, "--file=$git_dir/config",
395                         'include.path', '../../all.git/config');
396         PublicInbox::Import::run_die(\@cmd);
397
398         my $alt = "$all/objects/info/alternates";
399         my $new_obj_dir = "../../git/$new.git/objects";
400         my %alts;
401         if (-e $alt) {
402                 open(my $fh, '<', $alt) or die "open < $alt: $!\n";
403                 %alts = map { chomp; $_ => 1 } (<$fh>);
404         }
405         return $git_dir if $alts{$new_obj_dir};
406         open my $fh, '>>', $alt or die "open >> $alt: $!\n";
407         print $fh "$new_obj_dir\n" or die "print >> $alt: $!\n";
408         close $fh or die "close $alt: $!\n";
409         $git_dir
410 }
411
412 sub git_dir_latest {
413         my ($self, $max) = @_;
414         $$max = -1;
415         my $pfx = "$self->{-inbox}->{mainrepo}/git";
416         return unless -d $pfx;
417         my $latest;
418         opendir my $dh, $pfx or die "opendir $pfx: $!\n";
419         while (defined(my $git_dir = readdir($dh))) {
420                 $git_dir =~ m!\A(\d+)\.git\z! or next;
421                 if ($1 > $$max) {
422                         $$max = $1;
423                         $latest = "$pfx/$git_dir";
424                 }
425         }
426         $latest;
427 }
428
429 sub importer {
430         my ($self) = @_;
431         my $im = $self->{im};
432         if ($im) {
433                 if ($im->{bytes_added} < $self->{rotate_bytes}) {
434                         return $im;
435                 } else {
436                         $self->{im} = undef;
437                         $im->done;
438                         $self->searchidx_checkpoint(1);
439                         $im = undef;
440                         my $git_dir = $self->git_init(++$self->{max_git});
441                         my $git = PublicInbox::Git->new($git_dir);
442                         return $self->import_init($git, 0);
443                 }
444         }
445         my $new = 0;
446         my $max;
447         my $latest = git_dir_latest($self, \$max);
448         if (defined $latest) {
449                 my $git = PublicInbox::Git->new($latest);
450                 my $packed_bytes = $git->packed_bytes;
451                 if ($packed_bytes >= $self->{rotate_bytes}) {
452                         $new = $max + 1;
453                 } else {
454                         $self->{max_git} = $max;
455                         return $self->import_init($git, $packed_bytes);
456                 }
457         }
458         $self->{max_git} = $new;
459         $latest = $self->git_init($new);
460         $self->import_init(PublicInbox::Git->new($latest), 0);
461 }
462
463 sub import_init {
464         my ($self, $git, $packed_bytes) = @_;
465         my $im = PublicInbox::Import->new($git, undef, undef, $self->{-inbox});
466         $im->{bytes_added} = int($packed_bytes / $PACKING_FACTOR);
467         $im->{want_object_info} = 1;
468         $im->{lock_path} = undef;
469         $im->{path_type} = 'v2';
470         $self->{im} = $im;
471 }
472
473 # XXX experimental
474 sub diff ($$$) {
475         my ($mid, $cur, $new) = @_;
476         use File::Temp qw(tempfile);
477         use PublicInbox::Spawn qw(spawn);
478
479         my ($ah, $an) = tempfile('email-cur-XXXXXXXX', TMPDIR => 1);
480         print $ah $cur->as_string or die "print: $!";
481         close $ah or die "close: $!";
482         my ($bh, $bn) = tempfile('email-new-XXXXXXXX', TMPDIR => 1);
483         PublicInbox::Import::drop_unwanted_headers($new);
484         print $bh $new->as_string or die "print: $!";
485         close $bh or die "close: $!";
486         my $cmd = [ qw(diff -u), $an, $bn ];
487         print STDERR "# MID conflict <$mid>\n";
488         my $pid = spawn($cmd, undef, { 1 => 2 });
489         defined $pid or die "diff failed to spawn $!";
490         waitpid($pid, 0) == $pid or die "diff did not finish";
491         unlink($an, $bn);
492 }
493
494 sub lookup_content {
495         my ($self, $mime, $mid) = @_;
496         my $ibx = $self->{-inbox};
497
498         my $srch = $ibx->search->reopen;
499         my $cid = content_id($mime);
500         my $found;
501         $srch->each_smsg_by_mid($mid, sub {
502                 my ($smsg) = @_;
503                 $smsg->load_expand;
504                 my $msg = $ibx->msg_by_smsg($smsg);
505                 if (!defined($msg)) {
506                         warn "broken smsg for $mid\n";
507                         return 1; # continue
508                 }
509                 my $cur = PublicInbox::MIME->new($msg);
510                 if (content_id($cur) eq $cid) {
511                         $smsg->{mime} = $cur;
512                         $found = $smsg;
513                         return 0; # break out of loop
514                 }
515
516                 # XXX DEBUG_DIFF is experimental and may be removed
517                 diff($mid, $cur, $mime) if $ENV{DEBUG_DIFF};
518
519                 1; # continue
520         });
521         $found;
522 }
523
524 sub atfork_child {
525         my ($self) = @_;
526         my $fh = delete $self->{reindex_pipe};
527         close $fh if $fh;
528         if (my $parts = $self->{idx_parts}) {
529                 $_->atfork_child foreach @$parts;
530         }
531         if (my $im = $self->{im}) {
532                 $im->atfork_child;
533         }
534         die "unexpected mm" if $self->{mm};
535 }
536
537 sub mark_deleted {
538         my ($self, $D, $git, $oid) = @_;
539         my $msgref = $git->cat_file($oid);
540         my $mime = PublicInbox::MIME->new($$msgref);
541         my $mids = mids($mime->header_obj);
542         my $cid = content_id($mime);
543         foreach my $mid (@$mids) {
544                 $D->{"$mid\0$cid"} = 1;
545         }
546 }
547
548 sub reindex_oid {
549         my ($self, $mm_tmp, $D, $git, $oid, $regen) = @_;
550         my $len;
551         my $msgref = $git->cat_file($oid, \$len);
552         my $mime = PublicInbox::MIME->new($$msgref);
553         my $mids = mids($mime->header_obj);
554         my $cid = content_id($mime);
555
556         # get the NNTP article number we used before, highest number wins
557         # and gets deleted from mm_tmp;
558         my $mid0;
559         my $num = -1;
560         my $del = 0;
561         foreach my $mid (@$mids) {
562                 $del += (delete $D->{"$mid\0$cid"} || 0);
563                 my $n = $mm_tmp->num_for($mid);
564                 if (defined $n && $n > $num) {
565                         $mid0 = $mid;
566                         $num = $n;
567                 }
568         }
569         if (!defined($mid0) && $regen && !$del) {
570                 $num = $$regen--;
571                 die "BUG: ran out of article numbers\n" if $num <= 0;
572                 my $mm = $self->{mm};
573                 foreach my $mid (reverse @$mids) {
574                         if ($mm->mid_set($num, $mid) == 1) {
575                                 $mid0 = $mid;
576                                 last;
577                         }
578                 }
579                 if (!defined($mid0)) {
580                         my $id = '<' . join('> <', @$mids) . '>';
581                         warn "Message-ID $id unusable for $num\n";
582                         foreach my $mid (@$mids) {
583                                 defined(my $n = $mm->num_for($mid)) or next;
584                                 warn "#$n previously mapped for <$mid>\n";
585                         }
586                 }
587         }
588
589         if (!defined($mid0) || $del) {
590                 if (!defined($mid0) && $del) { # expected for deletes
591                         $$regen--;
592                         return
593                 }
594
595                 my $id = '<' . join('> <', @$mids) . '>';
596                 defined($mid0) or
597                         warn "Skipping $id, no article number found\n";
598                 if ($del && defined($mid0)) {
599                         warn "$id was deleted $del " .
600                                 "time(s) but mapped to article #$num\n";
601                 }
602                 return;
603
604         }
605         $mm_tmp->mid_delete($mid0) or
606                 die "failed to delete <$mid0> for article #$num\n";
607
608         my $nparts = $self->{partitions};
609         my $part = $num % $nparts;
610         my $idx = $self->idx_part($part);
611         $idx->index_raw($len, $msgref, $num, $oid, $mid0, $mime);
612         my $n = $self->{transact_bytes} += $len;
613         if ($n > (PublicInbox::SearchIdx::BATCH_BYTES * $nparts)) {
614                 $git->cleanup;
615                 $mm_tmp->atfork_prepare;
616                 $self->done; # release lock
617                 # allow -watch or -mda to write...
618                 $self->idx_init; # reacquire lock
619                 $mm_tmp->atfork_parent;
620         }
621 }
622
623 sub reindex {
624         my ($self, $regen) = @_;
625         my $ibx = $self->{-inbox};
626         my $pfx = "$ibx->{mainrepo}/git";
627         my $max_git;
628         my $latest = git_dir_latest($self, \$max_git);
629         return unless defined $latest;
630         my $head = $ibx->{ref_head} || 'refs/heads/master';
631         $self->idx_init; # acquire lock
632         my $x40 = qr/[a-f0-9]{40}/;
633         my $mm_tmp = $self->{mm}->tmp_clone;
634         if (!$regen) {
635                 my (undef, $max) = $mm_tmp->minmax;
636                 unless (defined $max) {
637                         $regen = 1;
638                         warn
639 "empty msgmap.sqlite3, regenerating article numbers\n";
640                 }
641         }
642         my $tip; # latest commit out of all git repos
643         if ($regen) {
644                 my $regen_max = 0;
645                 for (my $cur = $max_git; $cur >= 0; $cur--) {
646                         die "already reindexing!\n" if $self->{reindex_pipe};
647                         my $git = PublicInbox::Git->new("$pfx/$cur.git");
648                         -d $git->{git_dir} or next; # missing parts are fine
649                         chomp($tip = $git->qx('rev-parse', $head)) unless $tip;
650                         my $h = $cur == $max_git ? $tip : $head;
651
652                         # can't use 'rev-list --count' if we use --diff-filter
653                         my $fh = $git->popen(qw(log --pretty=tformat:%h
654                                         --no-notes --no-color --no-renames
655                                         --diff-filter=AM), $h, '--', 'm');
656                         ++$regen_max while <$fh>;
657                 }
658                 die "No messages found in $pfx/*.git, bug?\n" unless $regen_max;
659                 $regen = \$regen_max;
660         }
661         my $D = {};
662         my @cmd = qw(log --raw -r --pretty=tformat:%h
663                         --no-notes --no-color --no-abbrev --no-renames);
664
665         # if we are regenerating, we must not use a newer tip commit than what
666         # the regeneration counter used:
667         $tip ||= $head;
668
669         # work backwards through history
670         for (my $cur = $max_git; $cur >= 0; $cur--) {
671                 die "already reindexing!\n" if delete $self->{reindex_pipe};
672                 my $cmt;
673                 my $git_dir = "$pfx/$cur.git";
674                 -d $git_dir or next; # missing parts are fine
675                 my $git = PublicInbox::Git->new($git_dir);
676                 my $h = $cur == $max_git ? $tip : $head;
677                 my $fh = $self->{reindex_pipe} = $git->popen(@cmd, $h);
678                 while (<$fh>) {
679                         if (/\A$x40$/o) {
680                                 chomp($cmt = $_);
681                         } elsif (/\A:\d{6} 100644 $x40 ($x40) [AM]\tm$/o) {
682                                 $self->reindex_oid($mm_tmp, $D, $git, $1,
683                                                 $regen);
684                         } elsif (/\A:\d{6} 100644 $x40 ($x40) [AM]\td$/o) {
685                                 $self->mark_deleted($D, $git, $1);
686                         }
687                 }
688                 delete $self->{reindex_pipe};
689         }
690         my $gaps;
691         if ($regen && $$regen != 0) {
692                 warn "W: leftover article number ($$regen)\n";
693                 $gaps = 1;
694         }
695         my ($min, $max) = $mm_tmp->minmax;
696         if (defined $max) {
697                 warn "W: leftover article numbers at $min..$max\n";
698                 $gaps = 1;
699         }
700         warn "W: were old git partitions deleted?\n" if $gaps;
701         my @d = sort keys %$D;
702         if (@d) {
703                 warn "BUG: ", scalar(@d)," unseen deleted messages marked\n";
704                 foreach (@d) {
705                         my ($mid, undef) = split(/\0/, $_, 2);
706                         warn "<$mid>\n";
707                 }
708         }
709 }
710
711 1;