From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 89E49205D2 for ; Thu, 23 May 2019 09:37:09 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 13/26] v2writable: hoist out log_range sub for readability Date: Thu, 23 May 2019 09:36:51 +0000 Message-Id: <20190523093704.18367-14-e@80x24.org> In-Reply-To: <20190523093704.18367-1-e@80x24.org> References: <20190523093704.18367-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This is preparation to to support partial reindexing --- lib/PublicInbox/V2Writable.pm | 72 ++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index c476cb3..3dd606e 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 ||= {}; -- EW