-sub prepare_range_stack {
- my ($git, $sync, $range) = @_;
- # Don't bump num_highwater on --reindex by using {D}.
- # We intentionally do NOT use {D} in the non-reindex case because
- # we want NNTP article number gaps from unindexed messages to
- # show up in mirrors, too.
- my $D = $sync->{D} //= $sync->{reindex} ? {} : undef; # OID_BIN => NR
-
- my $fh = $git->popen(qw(log --raw -r --pretty=tformat:%at-%ct-%H
- --no-notes --no-color --no-renames --no-abbrev),
- $range);
- my ($at, $ct, $stk);
- while (<$fh>) {
- if (/\A([0-9]+)-([0-9]+)-($x40)$/o) {
- ($at, $ct) = ($1 + 0, $2 + 0);
- $stk //= PublicInbox::IdxStack->new($3);
- } elsif (/\A:\d{6} 100644 $x40 ($x40) [AM]\td$/o) {
- my $oid = $1;
- if ($D) { # reindex case
- $D->{pack('H*', $oid)}++;
- } else { # non-reindex case:
- $stk->push_rec('d', $at, $ct, $oid);
- }
- } elsif (/\A:\d{6} 100644 $x40 ($x40) [AM]\tm$/o) {
- my $oid = $1;
- if ($D) {
- my $oid_bin = pack('H*', $oid);
- my $nr = --$D->{$oid_bin};
- delete($D->{$oid_bin}) if $nr <= 0;
-
- # nr < 0 (-1) means it never existed
- $stk->push_rec('m', $at, $ct, $oid) if $nr < 0;
- } else {
- $stk->push_rec('m', $at, $ct, $oid);
- }
- }
- }
- close $fh or die "git log failed: \$?=$?";
- $stk ? $stk->read_prepare : undef;
-}
-