dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] solver: reduce path lookups for `git'
Date: Tue, 28 Nov 2023 10:49:38 +0000	[thread overview]
Message-ID: <20231128104938.1378689-1-e@80x24.org> (raw)

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"

                 reply	other threads:[~2023-11-28 10:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231128104938.1378689-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.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).