about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-05-23 09:36:51 +0000
committerEric Wong <e@80x24.org>2019-05-23 17:43:50 +0000
commita1c3fb1bbef319a0af8ab63380495984c3a4ee18 (patch)
treecbef2d5c99878cfeea038ef583a86467da07b7cd
parent371f00f2f0698915b49599a834696c7ae3631ce7 (diff)
downloadpublic-inbox-a1c3fb1bbef319a0af8ab63380495984c3a4ee18.tar.gz
This is preparation to to support partial reindexing
-rw-r--r--lib/PublicInbox/V2Writable.pm72
1 files changed, 37 insertions, 35 deletions
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index c476cb39..3dd606ea 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -808,6 +808,40 @@ sub last_commits {
 
 *is_ancestor = *PublicInbox::SearchIdx::is_ancestor;
 
+# returns a revision range for git-log(1)
+sub log_range ($$$$$) {
+        my ($self, $git, $ranges, $i, $tip) = @_;
+        my $cur = $ranges->[$i] or return $tip; # all of it
+        my $range = "$cur..$tip";
+        if (is_ancestor($git, $cur, $tip)) { # common case
+                my $n = $git->qx(qw(rev-list --count), $range);
+                chomp($n);
+                if ($n == 0) {
+                        $ranges->[$i] = undef;
+                        return; # nothing to do
+                }
+        } else {
+                warn <<"";
+discontiguous range: $range
+Rewritten history? (in $git->{git_dir})
+
+                chomp(my $base = $git->qx('merge-base', $tip, $cur));
+                if ($base) {
+                        $range = "$base..$tip";
+                        warn "found merge-base: $base\n"
+                } else {
+                        $range = $tip;
+                        warn "discarding history at $cur\n";
+                }
+                warn <<"";
+reindexing $git->{git_dir} starting at
+$range
+
+                $self->{"unindex-range.$i"} = "$base..$cur";
+        }
+        $range;
+}
+
 sub index_prepare {
         my ($self, $opts, $epoch_max, $ranges) = @_;
         my $regen_max = 0;
@@ -818,42 +852,9 @@ sub index_prepare {
                 -d $git_dir or next; # missing parts are fine
                 my $git = PublicInbox::Git->new($git_dir);
                 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";
-                        if (is_ancestor($git, $cur, $tip)) { # common case
-                                my $n = $git->qx(qw(rev-list --count), $range);
-                                chomp($n);
-                                if ($n == 0) {
-                                        $ranges->[$i] = undef;
-                                        next;
-                                }
-                        } else {
-                                warn <<"";
-discontiguous range: $range
-Rewritten history? (in $git_dir)
-
-                                my $base = $git->qx('merge-base', $tip, $cur);
-                                chomp $base;
-                                if ($base) {
-                                        $range = "$base..$tip";
-                                        warn "found merge-base: $base\n"
-                                } else {
-                                        $range = $tip;
-                                        warn <<"";
-discarding history at $cur
-
-                                }
-                                warn <<"";
-reindexing $git_dir starting at
-$range
 
-                                $self->{"unindex-range.$i"} = "$base..$cur";
-                        }
-                } else {
-                        $range = $tip; # all of it
-                }
+                next if $?; # new repo
+                my $range = log_range($self, $git, $ranges, $i, $tip) or next;
                 $ranges->[$i] = $range;
 
                 # can't use 'rev-list --count' if we use --diff-filter
@@ -923,6 +924,7 @@ sub unindex {
                 qw(-c gc.reflogExpire=now gc --prune=all)]);
 }
 
+# called for public-inbox-index
 sub index_sync {
         my ($self, $opts) = @_;
         $opts ||= {};