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,AWL,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 2A4101FA1A for ; Sat, 16 Oct 2021 01:01:04 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 08/12] extindex: prune invalid alternate entries on --gc Date: Sat, 16 Oct 2021 01:00:59 +0000 Message-Id: <20211016010103.30825-9-e@80x24.org> In-Reply-To: <20211016010103.30825-1-e@80x24.org> References: <20211016010103.30825-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Seeing the same warning over and over again gets annoying. --- lib/PublicInbox/ExtSearchIdx.pm | 8 ++++---- lib/PublicInbox/MultiGit.pm | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm index ba7588d53254..a08a94515582 100644 --- a/lib/PublicInbox/ExtSearchIdx.pm +++ b/lib/PublicInbox/ExtSearchIdx.pm @@ -1192,7 +1192,7 @@ sub idx_init { # similar to V2Writable $self->git->cleanup; my $mode = 0644; my $ALL = $self->git->{git_dir}; # topdir/ALL.git - my ($has_new, $alt, $seen); + my ($has_new, $alt, $seen, $prune, $prune_nr); if ($opt->{-private}) { # LeiStore my $local = "$self->{topdir}/local"; # lei/store $self->{mg} //= PublicInbox::MultiGit->new($self->{topdir}, @@ -1208,8 +1208,8 @@ sub idx_init { # similar to V2Writable } else { # extindex has no epochs $self->{mg} //= PublicInbox::MultiGit->new($self->{topdir}, 'ALL.git'); - ($alt, $seen) = $self->{mg}->read_alternates(\$mode, - $opt->{-idx_gc}); + $prune = $opt->{-idx_gc} ? \$prune_nr : undef; + ($alt, $seen) = $self->{mg}->read_alternates(\$mode, $prune); PublicInbox::Import::init_bare($ALL); } @@ -1243,7 +1243,7 @@ sub idx_init { # similar to V2Writable } $new .= "$d\n"; } - ($has_new || $new ne '') and + ($has_new || $prune_nr || $new ne '') and $self->{mg}->write_alternates($mode, $alt, $new); $git_midx and $self->with_umask(sub { my @cmd = ('multi-pack-index'); diff --git a/lib/PublicInbox/MultiGit.pm b/lib/PublicInbox/MultiGit.pm index 91d7998aa51f..9429a00ca64c 100644 --- a/lib/PublicInbox/MultiGit.pm +++ b/lib/PublicInbox/MultiGit.pm @@ -45,7 +45,11 @@ sub read_alternates { $alt{$rel} = $score; } else { warn "W: stat($dir) failed: $! ($f)"; - $alt{$rel} = $score unless $prune; + if ($prune) { + ++$$prune; + } else { + $alt{$rel} = $score; + } } } } elsif (!$!{ENOENT}) {