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 0B6EB1F677 for ; Fri, 27 Oct 2023 22:21:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1698445277; bh=1kZH2NWUy3UZOXhc+6hSaMgV0MyByaIBf5907E1hJrE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qrHWYu/e2e4LFc2/GXfG+8wqO3k0GU1GJCHaH9KXLnjwi2f8/11Mm5Z8eBwmmO61N bUmTptVnARrFJ1CcdEE5jZlYAA1hdjU4/4Fhh5vo1kaXsrhypq2yF2Oe8qOlxhVbHs nB9tnDC8fAogJUPvn4AhkywDlAtB7z7l5YlC9d2k= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 05/10] git: avoid extra stat(2) for git version Date: Fri, 27 Oct 2023 22:21:11 +0000 Message-ID: <20231027222116.4034363-6-e@80x24.org> In-Reply-To: <20231027222116.4034363-1-e@80x24.org> References: <20231027222116.4034363-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 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