From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 611DA1F452 for ; Tue, 28 Nov 2023 10:49:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1701168578; bh=fCijsW3VDmlY5CPAWKtz0jtUkDsbBUNg3aqFVNJ5Mfk=; h=From:To:Subject:Date:From; b=cmdzeNGlQfs3mCYF61koP9H+kMtfMI1glToFsz4afqSWu8BnLQVvs4tPd1cSfc1kj lZPDr2UFaqSH9B6kr7Kbm+K1meXGECV+5p1b5IoorBk9suVeWSpi6rCA5INftE/uIl WBzW4vfYUrEQF4m+skQ7GOGFhlWlS/sn6ktQcv/E= From: Eric Wong To: spew@80x24.org Subject: [PATCH] solver: reduce path lookups for `git' Date: Tue, 28 Nov 2023 10:49:38 +0000 Message-ID: <20231128104938.1378689-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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"