From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3E6511F4C4 for ; Tue, 12 Nov 2024 20:34:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1731443674; bh=qhn43xhIP3+M/3x2fqZWgh4gSeszDRJ7GJbSwCvjerg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dw9AnbGY0XT8qFPbJRCUPwJL3xBFO+xalcYD+j6ZeT2PAMxxz/8rux/d0sNNys3Of D4vJ+MGdmF6gy50uA3Z6w0vWuiPG0sgOolCqhx5jPbxvShl+fczqTgD9fdPYpaZUKO 0RIVrjg1AO6cXRrO4XkBqluUb9zg2z/qKzCAPsaE= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/4] cindex: rework path canonicalization check Date: Tue, 12 Nov 2024 20:34:30 +0000 Message-ID: <20241112203433.2515907-2-e@80x24.org> In-Reply-To: <20241112203433.2515907-1-e@80x24.org> References: <20241112203433.2515907-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm index ff3db8ba..13533a00 100644 --- a/lib/PublicInbox/CodeSearchIdx.pm +++ b/lib/PublicInbox/CodeSearchIdx.pm @@ -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 <{cidx_dir} not canonicalized: +EOM + warn "E: $d => $c\n"; + $d = $c; } if (defined(my $excl = $self->{-opt}->{exclude})) { my $re = '(?:'.join('\\z|', map {