From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/3] git: reduce spawning for rev-parse --git-path
Date: Thu, 30 May 2024 09:45:15 +0000 [thread overview]
Message-ID: <20240530094515.3402089-4-e@80x24.org> (raw)
In-Reply-To: <20240530094515.3402089-1-e@80x24.org>
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 | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 55005475..6b722023 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;
}
};
}
prev parent reply other threads:[~2024-05-30 9:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-30 9:45 [PATCH 0/3] reduce synchronous waitpid calls Eric Wong
2024-05-30 9:45 ` [PATCH 1/3] gcf2: eliminate unnecessary autodie::close import Eric Wong
2024-05-30 9:45 ` [PATCH 2/3] git: prefer WNOHANG for `git cat-file --batch-*' Eric Wong
2024-05-30 9:45 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240530094515.3402089-4-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).