]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
treewide: use cached git executable lookup
authorEric Wong <e@80x24.org>
Thu, 6 Jun 2024 07:44:15 +0000 (07:44 +0000)
committerEric Wong <e@80x24.org>
Fri, 7 Jun 2024 00:39:47 +0000 (00:39 +0000)
Repeated stat(2) syscalls are more expensive nowadays due
to CPU vulnerability mitigations and this change also
allows bypassing some heap allocations done by Perl.

14 files changed:
lib/PublicInbox/Admin.pm
lib/PublicInbox/Config.pm
lib/PublicInbox/GitCredential.pm
lib/PublicInbox/Import.pm
lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiBlob.pm
lib/PublicInbox/LeiConfig.pm
lib/PublicInbox/LeiInput.pm
lib/PublicInbox/LeiMailDiff.pm
lib/PublicInbox/LeiSavedSearch.pm
lib/PublicInbox/LeiViewText.pm
lib/PublicInbox/MailDiff.pm
lib/PublicInbox/MultiGit.pm
lib/PublicInbox/WwwCoderepo.pm

index a2045b37dea048a89f8febc210708a1cdefc8a4f..bb5d365327e7c54697342dd2ea4b8b7d964582bb 100644 (file)
@@ -11,6 +11,7 @@ use PublicInbox::Config;
 use PublicInbox::Inbox;
 use PublicInbox::Spawn qw(run_qx);
 use PublicInbox::Eml;
+use PublicInbox::Git qw(git_exe);
 *rel2abs_collapsed = \&PublicInbox::Config::rel2abs_collapsed;
 
 sub setup_signals {
@@ -77,7 +78,7 @@ sub resolve_git_dir {
        my $env;
        defined($pwd) && substr($cd // '/', 0, 1) ne '/' and
                $env->{PWD} = "$pwd/$cd";
-       my $cmd = [ qw(git rev-parse --git-dir) ];
+       my $cmd = [ git_exe, qw(rev-parse --git-dir) ];
        my $dir = run_qx($cmd, $env, { -C => $cd });
        die "error in @$cmd (cwd:${\($cd // '.')}): $?\n" if $?;
        chomp $dir;
index e18439120280abb1454722cf3a3b8e4345442524..998fc25e820cca4af63999eaa6095c063b18d058 100644 (file)
@@ -632,7 +632,7 @@ sub urlmatch {
                } elsif (($? >> 8) != 1) {
                        $urlmatch_broken = 1;
                } elsif ($try_git) { # n.b. this takes cwd into account
-                       $val = run_qx([qw(git config), @bool,
+                       $val = run_qx([$cmd->[0], 'config', @bool,
                                        qw(-z --get-urlmatch), $key, $url]);
                        undef $val if $?;
                }
index bb225ff320585385eb989f95fd1a6e181f14ff4b..cf5a2213431fb6f5240d8017b14322c107bd8b5a 100644 (file)
@@ -4,13 +4,14 @@
 # git-credential wrapper with built-in .netrc fallback
 package PublicInbox::GitCredential;
 use v5.12;
+use PublicInbox::Git qw(git_exe);
 use PublicInbox::Spawn qw(popen_rd);
 use autodie qw(close pipe);
 
 sub run ($$;$) {
        my ($self, $op, $lei) = @_;
        my ($in_r, $in_w, $out_r);
-       my $cmd = [ qw(git credential), $op ];
+       my $cmd = [ git_exe, 'credential', $op ];
        pipe($in_r, $in_w);
        if ($lei) { # we'll die if disconnected:
                pipe($out_r, my $out_w);
index fefc282a0e01336293188ecb76eb6146a1349b07..2e193d46479f5b76509c3a2c8da0ab8bf430c21a 100644 (file)
@@ -8,6 +8,7 @@
 package PublicInbox::Import;
 use v5.12;
 use parent qw(PublicInbox::Lock);
+use PublicInbox::Git qw(git_exe);
 use PublicInbox::Spawn qw(run_die run_qx spawn);
 use PublicInbox::MID qw(mids mid2path);
 use PublicInbox::Address;
@@ -24,7 +25,7 @@ use PublicInbox::IO qw(read_all);
 
 sub default_branch () {
        state $default_branch = do {
-               my $h = run_qx([qw(git config --global init.defaultBranch)],
+               my $h = run_qx([git_exe,qw(config --global init.defaultBranch)],
                                 { GIT_CONFIG => undef });
                chomp $h;
                $h eq '' ? 'refs/heads/master' : "refs/heads/$h";
index 309d290da4314808a23a6597c7b303ba2a945d1e..c5146428303eadb15c4e5d4ab59a07bce08c1e3b 100644 (file)
@@ -22,6 +22,7 @@ use PublicInbox::Syscall qw(EPOLLIN);
 use PublicInbox::Spawn qw(run_wait popen_rd run_qx);
 use PublicInbox::Lock;
 use PublicInbox::Eml;
+use PublicInbox::Git qw(git_exe);
 use PublicInbox::Import;
 use PublicInbox::ContentHash qw(git_sha);
 use PublicInbox::OnDestroy;
@@ -1098,7 +1099,7 @@ sub path_to_fd {
 # caller needs to "-t $self->{1}" to check if tty
 sub start_pager {
        my ($self, $new_env) = @_;
-       chomp(my $pager = run_qx([qw(git var GIT_PAGER)]));
+       chomp(my $pager = run_qx([git_exe, qw(var GIT_PAGER)]));
        warn "`git var PAGER' error: \$?=$?" if $?;
        return if $pager eq 'cat' || $pager eq '';
        $new_env //= {};
index 7b2ea4347838c59192ab13be5fd2b37e4f0690b8..31936c367c0f89b748bd7278af8217e19e6761f8 100644 (file)
@@ -10,14 +10,14 @@ use parent qw(PublicInbox::IPC);
 use PublicInbox::Spawn qw(run_wait run_qx which);
 use PublicInbox::DS;
 use PublicInbox::Eml;
-use PublicInbox::Git;
+use PublicInbox::Git qw(git_exe);
 use PublicInbox::IO qw(read_all);
 
 sub get_git_dir ($$) {
        my ($lei, $d) = @_;
        return $d if -d "$d/objects" && -d "$d/refs" && -e "$d/HEAD";
 
-       my $cmd = [ qw(git rev-parse --git-dir) ];
+       my $cmd = [ git_exe, qw(rev-parse --git-dir) ];
        my $opt = { '-C' => $d };
        if (defined($lei->{opt}->{cwd})) { # --cwd used, report errors
                $opt->{2} = $lei->{2};
index a50ff2b600006a8c81ed6145bdc2fd2b76b55b05..ae12249f26d1d8c60ad3181903f95a82326144e8 100644 (file)
@@ -3,6 +3,7 @@
 package PublicInbox::LeiConfig; # subclassed by LeiEditSearch
 use v5.12;
 use PublicInbox::PktOp;
+use PublicInbox::Git qw(git_exe);
 use Fcntl qw(SEEK_SET);
 use autodie qw(open seek);
 use PublicInbox::IO qw(read_all);
@@ -11,7 +12,7 @@ sub cfg_do_edit ($;$) {
        my ($self, $reason) = @_;
        my $lei = $self->{lei};
        $lei->pgr_err($reason) if defined $reason;
-       my $cmd = [ qw(git config --edit -f), $self->{-f} ];
+       my $cmd = [ git_exe, qw(config --edit -f), $self->{-f} ];
        my $env = { GIT_CONFIG => $self->{-f} };
        $self->cfg_edit_begin if $self->can('cfg_edit_begin');
        # run in script/lei foreground
index c388f7dc73fb3f29b2b28240564369fcb2c31f23..0a6aba82efa4fcc8d7af57cec530d07a2cf4a4ed 100644 (file)
@@ -5,6 +5,7 @@
 package PublicInbox::LeiInput;
 use v5.12;
 use PublicInbox::DS;
+use PublicInbox::Git qw(git_exe);
 use PublicInbox::Spawn qw(which popen_rd);
 use PublicInbox::InboxWritable qw(eml_from_path);
 
@@ -252,7 +253,8 @@ sub input_path_url {
                each_ibx_eml($self, $esrch, @args);
        } elsif ($self->{missing_ok} && !-e $input) { # don't ->fail
                if ($lei->{cmd} eq 'p2q') {
-                       my $fp = [ qw(git format-patch --stdout -1), $input ];
+                       my $fp = [ git_exe, qw(format-patch --stdout -1),
+                                       $input ];
                        my $rdr = { 2 => $lei->{2} };
                        my $fh = popen_rd($fp, undef, $rdr);
                        eval { $self->input_fh('eml', $fh, $input, @args) };
index af6ecf828758dc010b5eb8dc259a9b5bb5cc80cd..270de507365b9b753d3091baeb12cdb1827b7a58 100644 (file)
@@ -7,13 +7,14 @@ package PublicInbox::LeiMailDiff;
 use v5.12;
 use parent qw(PublicInbox::IPC PublicInbox::LeiInput PublicInbox::MailDiff);
 use PublicInbox::Spawn qw(run_wait);
+use PublicInbox::Git qw(git_exe);
 require PublicInbox::LeiRediff;
 
 sub diff_a ($$) {
        my ($self, $eml) = @_;
        my $dir = "$self->{tmp}/N".(++$self->{nr});
        $self->dump_eml($dir, $eml);
-       my $cmd = [ qw(git diff --no-index) ];
+       my $cmd = [ git_exe, qw(diff --no-index) ];
        my $lei = $self->{lei};
        PublicInbox::LeiRediff::_lei_diff_prepare($lei, $cmd);
        push @$cmd, qw(-- a), "N$self->{nr}";
index 1c8a1f73021b8e830e121ba8fd0ac2af68ea6605..c27b6f8654fecaaec8f0d2b4c56276a3f10ab754 100644 (file)
@@ -5,7 +5,7 @@
 package PublicInbox::LeiSavedSearch;
 use v5.12;
 use parent qw(PublicInbox::Lock);
-use PublicInbox::Git;
+use PublicInbox::Git qw(git_exe);
 use PublicInbox::OverIdx;
 use PublicInbox::LeiSearch;
 use PublicInbox::Config;
@@ -176,7 +176,7 @@ sub description { $_[0]->{qstr} } # for WWW
 sub cfg_set { # called by LeiXSearch
        my ($self, @args) = @_;
        my $lk = $self->lock_for_scope; # git-config doesn't wait
-       run_die([qw(git config -f), $self->{'-f'}, @args]);
+       run_die([git_exe, qw(config -f), $self->{'-f'}, @args]);
 }
 
 # drop-in for LeiDedupe API
index c7d72c71cf464a1318752cdc9af53c8114ec458a..6510b19ec52d2e2e744bc8945ee535796752efc6 100644 (file)
@@ -12,6 +12,7 @@ use PublicInbox::View;
 use PublicInbox::Hval;
 use PublicInbox::ViewDiff;
 use PublicInbox::Spawn qw(popen_rd);
+use PublicInbox::Git qw(git_exe);
 use Term::ANSIColor;
 use POSIX ();
 use PublicInbox::Address;
@@ -72,7 +73,7 @@ sub new {
        my $self = bless { %{$lei->{opt}}, -colored => \&uncolored }, $cls;
        $self->{-quote_reply} = 1 if $fmt eq 'reply';
        return $self unless $self->{color} //= -t $lei->{1};
-       my @cmd = qw(git config -z --includes -l); # reuse normal git config
+       my @cmd = (git_exe, qw(config -z --includes -l)); # reuse normal git cfg
        my $r = popen_rd(\@cmd, undef, { 2 => $lei->{2} });
        my $cfg = PublicInbox::Config::config_fh_parse($r, "\0", "\n");
        if (!$r->close) {
index 125360fee6be6d5eb7d322efe4e2aea95e77213d..ce268bfb734dc654828d8c7ef556e3ff1777e741 100644 (file)
@@ -7,6 +7,7 @@ use PublicInbox::ContentHash qw(content_digest);
 use PublicInbox::MsgIter qw(msg_part_text);
 use PublicInbox::ViewDiff qw(flush_diff);
 use PublicInbox::GitAsyncCat;
+use PublicInbox::Git qw(git_exe);
 use PublicInbox::ContentDigestDbg;
 use PublicInbox::Qspawn;
 use PublicInbox::IO qw(write_file);
@@ -81,7 +82,7 @@ sub do_diff {
        my $n = 'N'.(++$self->{nr});
        my $dir = "$self->{tmp}/$n";
        $self->dump_eml($dir, $eml);
-       my $cmd = [ qw(git diff --no-index --no-color -- a), $n ];
+       my $cmd = [ git_exe, qw(diff --no-index --no-color -- a), $n ];
        my $opt = { -C => "$self->{tmp}", quiet => 1 };
        my $qsp = PublicInbox::Qspawn->new($cmd, undef, $opt);
        $qsp->psgi_qx($self->{ctx}->{env}, undef, \&emit_msg_diff, $self);
index b769180600ac5d46207bbc6acfaa3fd25fc0c7f4..32bb3588041d6316a208cdc0c636b1729004176e 100644 (file)
@@ -7,6 +7,7 @@ use strict;
 use v5.10.1;
 use PublicInbox::Spawn qw(run_die run_qx);
 use PublicInbox::Import;
+use PublicInbox::Git qw(git_exe);
 use File::Temp 0.19;
 use List::Util qw(max);
 use PublicInbox::IO qw(read_all);
@@ -110,11 +111,12 @@ sub epoch_cfg_set {
        my ($self, $epoch_nr) = @_;
        my $f = epoch_dir($self)."/$epoch_nr.git/config";
        my $v = "../../$self->{all}/config";
+       my @cmd = (git_exe, qw(config -f), $f, 'include.path');
        if (-r $f) {
-               chomp(my $x = run_qx([qw(git config -f), $f, 'include.path']));
+               chomp(my $x = run_qx(\@cmd));
                return if $x eq $v;
        }
-       run_die([qw(git config -f), $f, 'include.path', $v ]);
+       run_die [@cmd, $v];
 }
 
 sub add_epoch {
index 8d82528496c70c030856a2bd39e87086d247b725..5e086feec29db19d1e1024ec5b0b9d5bc680afa8 100644 (file)
@@ -24,8 +24,9 @@ use PublicInbox::OnDestroy;
 use URI::Escape qw(uri_escape_utf8);
 use File::Spec;
 use autodie qw(fcntl open);
+use PublicInbox::Git qw(git_exe);
 
-my @EACH_REF = (qw(git for-each-ref --sort=-creatordate),
+my @EACH_REF = (git_exe, qw(for-each-ref --sort=-creatordate),
                "--format=%(HEAD)%00".join('%00', map { "%($_)" }
                qw(objectname refname:short subject creatordate:short)));
 my $HEADS_CMD = <<'';
@@ -249,7 +250,7 @@ sub summary ($$) {
        my $qsp_err = \($ctx->{-qsp_err} = '');
        my %opt = (quiet => 1, 2 => $ctx->{wcr}->{log_fh});
        my %env = (GIT_DIR => $ctx->{git}->{git_dir});
-       my @log = (qw(git log), "-$nl", '--pretty=format:%d %H %h %cs %s');
+       my @log = (git_exe, 'log', "-$nl", '--pretty=format:%d %H %h %cs %s');
        push(@log, $tip) if defined $tip;
 
        # limit scope for MockHTTP test (t/solver_git.t)