about summary refs log tree commit homepage
path: root/lib/PublicInbox/Fetch.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2024-05-09 00:39:01 +0000
committerEric Wong <e@80x24.org>2024-05-09 03:08:01 +0000
commit39c390da4f5793bdd08a3634ca34ed9c9bda0700 (patch)
tree75d879b15388519020222eeff485a479469513ac /lib/PublicInbox/Fetch.pm
parentcf3df165033bf36631bd890fa2375339cd95c593 (diff)
downloadpublic-inbox-master.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/Fetch.pm')
-rw-r--r--lib/PublicInbox/Fetch.pm11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/PublicInbox/Fetch.pm b/lib/PublicInbox/Fetch.pm
index b0f1437c..814d6e8e 100644
--- a/lib/PublicInbox/Fetch.pm
+++ b/lib/PublicInbox/Fetch.pm
@@ -12,6 +12,7 @@ use PublicInbox::LeiCurl;
 use PublicInbox::LeiMirror;
 use PublicInbox::SHA qw(sha_all);
 use File::Temp ();
+use PublicInbox::Git qw(git_exe);
 
 sub new { bless {}, __PACKAGE__ }
 
@@ -19,7 +20,7 @@ sub remote_url ($$) {
         my ($lei, $dir) = @_;
         my $rn = $lei->{opt}->{'try-remote'} // [ 'origin', '_grokmirror' ];
         for my $r (@$rn) {
-                my $cmd = [ qw(git config), "remote.$r.url" ];
+                my $cmd = [ git_exe, 'config', "remote.$r.url" ];
                 my $url = run_qx($cmd, undef, { -C => $dir, 2 => $lei->{2} });
                 next if $?;
                 $url =~ s!/*\n!!s;
@@ -92,7 +93,7 @@ sub do_manifest ($$$) {
 
 sub get_fingerprint2 {
         my ($git_dir) = @_;
-        my $rd = popen_rd([qw(git show-ref)], undef, { -C => $git_dir });
+        my $rd = popen_rd([git_exe, 'show-ref'], undef, { -C => $git_dir });
         sha_all(256, $rd)->digest; # ignore show-ref errors
 }
 
@@ -132,8 +133,8 @@ sub do_fetch { # main entry point
                                 warn "W: $edir missing remote.*.url\n";
                                 my $o = { -C => $edir };
                                 $o->{1} = $o->{2} = $lei->{2};
-                                run_wait([qw(git config -l)], undef, $o) and
-                                        $lei->child_error($?);
+                                run_wait([git_exe, qw(config -l)], undef, $o)
+                                        and $lei->child_error($?);
                         }
                 }
                 @epochs = grep { !$skip->{$_} } @epochs if $skip;
@@ -188,7 +189,7 @@ EOM
                 my $opt = {}; # for spawn
                 if (-d $d) {
                         $fp2->[0] = get_fingerprint2($d) if $fp2;
-                        $cmd = [ @$torsocks, 'git', "--git-dir=$d",
+                        $cmd = [ @$torsocks, git_exe, "--git-dir=$d",
                                PublicInbox::LeiMirror::fetch_args($lei, $opt)];
                 } else {
                         my $e_uri = $ibx_uri->clone;