]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
git: reduce spawning for rev-parse --git-path
authorEric Wong <e@80x24.org>
Thu, 30 May 2024 09:45:15 +0000 (09:45 +0000)
committerEric Wong <e@80x24.org>
Fri, 31 May 2024 03:18:53 +0000 (03:18 +0000)
Since every non-worktree git repo has an `objects' directory, we
can quickly stat(2) to check for its presence and avoid an
expensive process spawn.  This should be the common case on
servers since it's rare to use worktrees on servers for
coderepos (or inboxes).

lib/PublicInbox/Git.pm

index 55005475b288f478483c5443ea505befcd5766e7..6b722023ab7ed0a9d1bee9d1171c934466433c6d 100644 (file)
@@ -108,9 +108,10 @@ sub new {
 sub git_path ($$) {
        my ($self, $path) = @_;
        $self->{-git_path}->{$path} //= do {
-               my $d = "$self->{git_dir}/$path";
-               if (-e $d) {
-                       $d;
+               my $d = $self->{git_dir};
+               my $f = "$d/$path";
+               if (-d "$d/objects") {
+                       $f;
                } else {
                        local $/ = "\n";
                        my $rdr = { 2 => \my $err };
@@ -119,7 +120,7 @@ sub git_path ($$) {
                        chomp $s;
 
                        # git prior to 2.5.0 did not understand --git-path
-                       $s eq "--git-path\n$path" ? $d : $s;
+                       $s eq "--git-path\n$path" ? $f : $s;
                }
        };
 }