]> Sergey Matveev's repositories - public-inbox.git/commitdiff
extindex: prune invalid alternate entries on --gc
authorEric Wong <e@80x24.org>
Sat, 16 Oct 2021 01:00:59 +0000 (01:00 +0000)
committerEric Wong <e@80x24.org>
Sat, 16 Oct 2021 01:42:53 +0000 (01:42 +0000)
Seeing the same warning over and over again gets annoying.

lib/PublicInbox/ExtSearchIdx.pm
lib/PublicInbox/MultiGit.pm

index ba7588d53254c092f735994f309f722874ff3618..a08a9451558244f39818c1f9a7170c799d083909 100644 (file)
@@ -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');
index 91d7998aa51f244e45d55b4515904464086d814c..9429a00ca64cfa3339608ec0f9f48c592a5cbaaa 100644 (file)
@@ -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}) {