From: Eric Wong Date: Thu, 30 May 2024 09:45:15 +0000 (+0000) Subject: git: reduce spawning for rev-parse --git-path X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8937f45d74d07fc6d7723d8b2fc3ba1aed7624b;p=thirdparty%2Fpublic-inbox.git git: reduce spawning for rev-parse --git-path 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). --- diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 55005475b..6b722023a 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -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; } }; }