about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-11-28 14:56:22 +0000
committerEric Wong <e@80x24.org>2023-11-29 02:13:23 +0000
commit46c08b706123b79c7884d1cbd3252a7bd93b885e (patch)
treea3d248fe08afc462bec3006358e52356d09a1df6 /lib/PublicInbox
parent67ecd56a0aaf977fa1a22aa6e2378c9317c72549 (diff)
downloadpublic-inbox-46c08b706123b79c7884d1cbd3252a7bd93b885e.tar.gz
git: speed up ->git_path for non-worktrees
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%.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/Git.pm17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 7c6e15b7..a374649f 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -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;
         };
 }