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 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 C4D191F68D for ; Fri, 27 Oct 2023 01:14:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1698369284; bh=CUny6Ouvtz2E4V1B5WkdFTq9aD0ZaSCTz2xjcRVAkho=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qeZyOtAypOOmckkcIPJwClVHZJv3X9XMU7TBx+HPCv3Vgy9lTxL7rbrUP5VJxg2Jg jnTwCB/Uqeh5NqdbigcSppQGtqB974HrARPY3hgmu72gna4EuFSFhKxPpaeCvyAMPt 6hn5CGKB6vOXtEX+bDi3Q/HNgFUPlY1BG3lnR6RM= From: Eric Wong To: spew@80x24.org Subject: [PATCH 6/8] git: avoid extra stat(2) for git version Date: Fri, 27 Oct 2023 01:14:41 +0000 Message-ID: <20231027011443.3709841-6-e@80x24.org> In-Reply-To: <20231027011443.3709841-1-e@80x24.org> References: <20231027011443.3709841-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: No sane installer will update executable files in place due to ETXTBSY, SIGBUS, or similar errors on execve. So save ourselves a stat(2) call by relying on the special `CORE::stat(_)' case to reuse the cached result from the `-x FILE' filetest in which(). --- lib/PublicInbox/Git.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index b5adc1f4..a1d52118 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -17,7 +17,6 @@ use PublicInbox::Syscall qw(EPOLLIN EPOLLET); use Errno qw(EINTR EAGAIN); use File::Glob qw(bsd_glob GLOB_NOSORT); use File::Spec (); -use Time::HiRes qw(stat); use PublicInbox::Spawn qw(spawn popen_rd run_qx which); use PublicInbox::ProcessIONBF; use PublicInbox::Tmpfile; @@ -53,13 +52,13 @@ my %GIT_ESC = ( ); my %ESC_GIT = map { $GIT_ESC{$_} => $_ } keys %GIT_ESC; -my $EXE_ST = ''; # pack('dd', st_ctime, st_size); +my $EXE_ST = ''; # pack('dd', st_dev, st_ino); # no `q' in some 32-bit builds my ($GIT_EXE, $GIT_VER); sub check_git_exe () { $GIT_EXE = which('git') // die "git not found in $ENV{PATH}"; - my @st = stat($GIT_EXE) or die "stat($GIT_EXE): $!"; - my $st = pack('dd', $st[10], $st[7]); + my @st = stat(_) or die "stat($GIT_EXE): $!"; # can't do HiRes w/ _ + my $st = pack('dd', $st[0], $st[1]); if ($st ne $EXE_ST) { my $v = run_qx([ $GIT_EXE, '--version' ]); die "$GIT_EXE --version: \$?=$?" if $?; @@ -117,6 +116,7 @@ sub git_path ($$) { sub alternates_changed { my ($self) = @_; my $alt = git_path($self, 'objects/info/alternates'); + use Time::HiRes qw(stat); my @st = stat($alt) or return 0; # can't rely on 'q' on some 32-bit builds, but `d' works