]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
cindex: rework path canonicalization check
authorEric Wong <e@80x24.org>
Tue, 12 Nov 2024 20:34:30 +0000 (20:34 +0000)
committerEric Wong <e@80x24.org>
Fri, 15 Nov 2024 20:27:36 +0000 (20:27 +0000)
While reading the code, I noticed inadvertant `$_' use when the
loop iterator is  `$d'.  Using `$_' here would result in
uninitialized variable access.  I've yet to hit this case in
real-world access.

Furthermore, we can use a single pass to canonicalize existing
directories instead of relying on a grep block, first.

Finally, favor File::Spec::Functions since `->' method dispatch
is slower than normal subroutine calls by a small amount even
when both the package and method names are static and known
early in advance..

lib/PublicInbox/CodeSearchIdx.pm

index ff3db8badf0ca994f99bcb4671c2b7fb351da457..13533a00dd317d97e54fd066cdc0eed7941fc3f9 100644 (file)
@@ -56,7 +56,7 @@ use PublicInbox::PktOp;
 use PublicInbox::IPC qw(nproc_shards);
 use POSIX qw(WNOHANG SEEK_SET strftime);
 use File::Path ();
-use File::Spec ();
+use File::Spec::Functions qw(canonpath);
 use List::Util qw(max);
 use PublicInbox::SHA qw(sha256_hex sha_all);
 use PublicInbox::Search qw(xap_terms);
@@ -1341,15 +1341,15 @@ sub cidx_run { # main entry point
                delete $REINDEX->{lock_path};
                $REINDEX->dbh;
        }
-       my @nc = grep { File::Spec->canonpath($_) ne $_ } @{$self->{git_dirs}};
-       if (@nc) {
-               warn "E: BUG? paths in $self->{cidx_dir} not canonicalized:\n";
-               for my $d (@{$self->{git_dirs}}) {
-                       my $c = File::Spec->canonpath($_);
-                       warn "E: $d => $c\n";
-                       $d = $c;
-               }
-               warn "E: canonicalized and attempting to continue\n";
+       my $cwarn;
+       for my $d (@{$self->{git_dirs}}) {
+               my $c = canonpath $d;
+               next if $c eq $d;
+               $cwarn = warn <<EOM if !$cwarn;
+E: BUG? paths in $self->{cidx_dir} not canonicalized:
+EOM
+               warn "E: $d => $c\n";
+               $d = $c;
        }
        if (defined(my $excl = $self->{-opt}->{exclude})) {
                my $re = '(?:'.join('\\z|', map {