]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
git: speed up ->git_path for non-worktrees
authorEric Wong <e@80x24.org>
Tue, 28 Nov 2023 14:56:22 +0000 (14:56 +0000)
committerEric Wong <e@80x24.org>
Wed, 29 Nov 2023 02:13:23 +0000 (02:13 +0000)
Only worktrees need to use `git rev-parse --git-path', so avoid
the spawn overhead of a new process.  With the SolverGit.pm
limit on coderepo scans disabled and scanning over 800 git repos
for git@vger matches, this reduces up xt/solver.t times by
roughly 25%.

lib/PublicInbox/Git.pm

index 7c6e15b7c870080003fad236c89a955d1bfb0145..a374649f1809aaa40c9035fdb74cc382c765127e 100644 (file)
@@ -100,14 +100,17 @@ sub new {
 sub git_path ($$) {
        my ($self, $path) = @_;
        $self->{-git_path}->{$path} //= do {
-               local $/ = "\n";
-               chomp(my $str = $self->qx(qw(rev-parse --git-path), $path));
-
-               # git prior to 2.5.0 did not understand --git-path
-               if ($str eq "--git-path\n$path") {
-                       $str = "$self->{git_dir}/$path";
+               my $d = "$self->{git_dir}/$path";
+               if (-e $d) {
+                       $d;
+               } else {
+                       local $/ = "\n";
+                       my $s = $self->qx(qw(rev-parse --git-path), $path);
+                       chomp $s;
+
+                       # git prior to 2.5.0 did not understand --git-path
+                       $s eq "--git-path\n$path" ? $d : $s;
                }
-               $str;
        };
 }