dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] solver: reduce path lookups for `git'
@ 2023-11-28 10:49 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2023-11-28 10:49 UTC (permalink / raw)
  To: spew

This can save a few hundred stat(2) syscalls in xt/solver.t
for users with several steps in $PATH before finding the
git executable.  We could probably be much more aggressive,
here, since we wouldn't expect users to alter their git
installation path often.
---
 lib/PublicInbox/SolverGit.pm | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm
index 4e79f750..fc200149 100644
--- a/lib/PublicInbox/SolverGit.pm
+++ b/lib/PublicInbox/SolverGit.pm
@@ -38,6 +38,7 @@ my $OID_MIN = 7;
 # work fairly.  Other PSGI servers may have trouble, though.
 my $MAX_PATCH = 9999;
 
+my $GIT;
 my $LF = qr!\r?\n!;
 my $ANY = qr![^\r\n]+!;
 my $MODE = '100644|120000|100755';
@@ -281,7 +282,7 @@ sub prepare_index ($) {
 
 	dbg($self, 'preparing index');
 	my $rdr = { 0 => $in };
-	my $cmd = [ qw(git update-index -z --index-info) ];
+	my $cmd = [ $GIT, qw(update-index -z --index-info) ];
 	my $qsp = PublicInbox::Qspawn->new($cmd, $self->{git_env}, $rdr);
 	$path_a = git_quote($path_a);
 	$qsp->{qsp_err} = \($self->{-qsp_err} = '');
@@ -313,6 +314,7 @@ EOF
 			$_->git_path('objects')."\n"
 		} @{$self->{gits}};
 	my $tmp_git = $self->{tmp_git} = PublicInbox::Git->new($git_dir);
+	$GIT = $tmp_git->check_git_exe;
 	$tmp_git->{-tmp} = $self->{tmp};
 	$self->{git_env} = {
 		GIT_DIR => $git_dir,
@@ -462,7 +464,7 @@ sub apply_result ($$) { # qx_cb
 		skip_identical($self, $patches, $di->{oid_b});
 	}
 
-	my @cmd = qw(git ls-files -s -z);
+	my @cmd = ($GIT, qw(ls-files -s -z));
 	my $qsp = PublicInbox::Qspawn->new(\@cmd, $self->{git_env});
 	$self->{-cur_di} = $di;
 	$qsp->{qsp_err} = \($self->{-qsp_err} = '');
@@ -474,7 +476,7 @@ sub do_git_apply ($) {
 	my $patches = $self->{patches};
 
 	# we need --ignore-whitespace because some patches are CRLF
-	my @cmd = (qw(git apply --cached --ignore-whitespace
+	my @cmd = ($GIT, qw(apply --cached --ignore-whitespace
 			--unidiff-zero --whitespace=warn --verbose));
 	my $len = length(join(' ', @cmd));
 	my $di; # keep track of the last one for "git ls-files"

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-28 10:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-28 10:49 [PATCH] solver: reduce path lookups for `git' Eric Wong

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).