From 39c390da4f5793bdd08a3634ca34ed9c9bda0700 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 9 May 2024 00:39:01 +0000 Subject: treewide: reduce $PATH checks for `git' executable Repeatedly checking $PATH for `git' when we need to call it multiple times in quick succession doesn't seem useful. So avoid some expensive stat(2) syscalls to make things less bad for systems which require expensive CPU vulnerability mitigations. This also saves a bunch of memory allocations since we do the $PATH lookup in pure Perl to avoid doing the uncacheable lookup in a vfork-ed child. --- lib/PublicInbox/Config.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox/Config.pm') diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index d6300610..49659a2e 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -13,6 +13,7 @@ use v5.10.1; use parent qw(Exporter); our @EXPORT_OK = qw(glob2re rel2abs_collapsed); use PublicInbox::Inbox; +use PublicInbox::Git qw(git_exe); use PublicInbox::Spawn qw(popen_rd run_qx); our $LD_PRELOAD = $ENV{LD_PRELOAD}; # only valid at startup our $DEDUPE; # set to {} to dedupe or clear cache @@ -188,7 +189,7 @@ sub git_config_dump { unshift(@opt_c, '-c', "include.path=$file") if defined($file); tmp_cmd_opt(\%env, $opt); } - my @cmd = ('git', @opt_c, qw(config -z -l --includes)); + my @cmd = (git_exe, @opt_c, qw(config -z -l --includes)); push(@cmd, '-f', $file) if !@opt_c && defined($file); my $fh = popen_rd(\@cmd, \%env, $opt); my $rv = config_fh_parse($fh, "\0", "\n"); @@ -608,7 +609,7 @@ sub config_cmd { my ($self, $env, $opt) = @_; my $f = $self->{-f} // default_file(); my @opt_c = @{$self->{-opt_c} // []}; - my @cmd = ('git', @opt_c, 'config'); + my @cmd = (git_exe, @opt_c, 'config'); @opt_c ? tmp_cmd_opt($env, $opt) : push(@cmd, '-f', $f); \@cmd; } -- cgit v1.2.3-24-ge0c7