- my $fcount = 0;
- my $pr = $opts->{-progress};
- $pr->("counting changes\n\t$range ... ") if $pr;
- # can't use 'rev-list --count' if we use --diff-filter
- my $fh = $git->popen(qw(log --pretty=tformat:%h
- --no-notes --no-color --no-renames
- --diff-filter=AM), $range);
- ++$fcount while <$fh>;
- close $fh or die "git log failed: \$?=$?";
- my $high = $self->{mm}->num_highwater;
- $pr->("$fcount\n") if $pr; # continue previous line
- $self->{ntodo} = $fcount;
-
- if (index($range, '..') < 0) {
- if ($high && $high == $fcount) {
- # fix up old bugs in full indexes which caused messages to
- # not appear in Msgmap
- $self->{regen_up} = $high;
- } else {
- # normal regen is for for fresh data
- $self->{regen_down} = $fcount;
- $self->{regen_down} += $high unless $opts->{reindex};
+ 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]+)-($OID)$/o) {
+ ($at, $ct) = ($1 + 0, $2 + 0);
+ $stk //= PublicInbox::IdxStack->new($3);
+ } elsif (/$delmsg/) {
+ my $oid = $1;
+ if ($D) { # reindex case
+ $D->{pack('H*', $oid)}++;
+ } else { # non-reindex case:
+ $stk->push_rec('d', $at, $ct, $oid);
+ }
+ } elsif (/$addmsg/) {
+ 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);
+ }