From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=199.89.1.14 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796165649; b=dBEZh9GvASp2arbm9K2t2TXk0/cJu9qYoSf5Z4GndNxvPic66BeLMCZCL9N2J9cO1fT2 FtewMq4MiLPbm2SzQorrbzCHja+iGqIcoPa7EXvlex96GQKxw3AHNgbBWQGxSVQPERaQP mYWuJI11xQ7NWtrGYVhu5MNmWKuk2pxuorDHvlGUzA8+K934tyKwRGdpSua9W5b2MR/z8 yqztRe5EncelEYbnOVdLIZsVpdJO6J/9lhWDDpex4gf77l8SRcyKqIuLgQNfwrN3PeyrD itG+2sIwlSiklu/RkyVt4AinEAYBpD4srk3kmchqRgPb0xBq7T7j/ZdH8pyx/7hwXFw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796165649; h=DMARC-Filter:Received:DKIM-Signature:X-Virus-Scanned:Received: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; bh=2DUQCH2rf7+kTs5opZ2hvQbdGe7qjkABL2jjKjmmP6g=; b=ww5dLvfh5ioF2tndWnD5Rmm1H5xZtl/WQ2QM+pqc+yO/CJOF9cLImUva4k5nyh7Qk4Tn hg8QxiGQLutdS/jhJc+KdSS0V3SAIcDZC9jRUfyg/RCAxIB5W+imQ5B5Y0z7qPfDlXe3q ywL5dOK0cNP2ZBSUOlfzRW1c4qfMklCZq4UMoh7NX/H/AgbMJgS7D7oXzdA4RvzHk7cPF snmqTOn8I/18PBZwnygqvAwWxKjeE4Nj2hqL3V2q5aaOJMupQdpjh+FEjh7kL3PhM4rs0 JEHHrZ3arrsNE0tFuXOT1gYayXYmhsJhFTDLxQE+W8TRLJ48r10liKpDLHFq3JvKHNg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=YQPnUd90; arc=none smtp.remote-ip=199.89.1.14 Received: from 011.lax.mailroute.net (011.lax.mailroute.net [199.89.1.14]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30E0C606A684 for ; Tue, 1 Dec 2026 22:54:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 30E0C606A684 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=YQPnUd90 Received: from localhost (localhost [127.0.0.1]) by 011.lax.mailroute.net (Postfix) with ESMTP id 4jfGR46tLdz1XMYJH; Tue, 1 Dec 2026 22:54:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1796165645; x=1798757646; bh=2DUQC H2rf7+kTs5opZ2hvQbdGe7qjkABL2jjKjmmP6g=; b=YQPnUd90KLysJkSBrsSKB fggrx3NjDehWNUCtICsvaGpaXhvD7idAkRHw65LGiY6naNlLW9EATYf9iWEivijg BlFifGS+VddwSUtWApVSsRQM80UB8mybQ0uFy1jKsJpIfU0PfVaEDaXPZfHInM40 RPET52n6Vgbp/g3TdGByT01ODH/qprU421tLpK2w/q8OakA1X+Xl5quXfEgGPap2 /5Bm2J+J9tbRudV/wCLFZirtec3QmoLcxCsoV6+9l4qMWAV8SO+sxTEPpv/yKJa7 gCEh7bJn/Lpkwg5mBkwW5W7T8rd8/Aqd1HsLB2ZzBTlviMXwcEDaBsJs+O1e6N6b A== X-Virus-Scanned: by MailRoute Received: from 011.lax.mailroute.net ([127.0.0.1]) by localhost (011.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 9ddIMLvPgBlL; Tue, 1 Dec 2026 22:54:05 +0000 (UTC) Received: from bvanassche.c.googlers.com.com (57.237.82.34.bc.googleusercontent.com [34.82.237.57]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 011.lax.mailroute.net (Postfix) with ESMTPSA id 4jfGQz22yvz1XMYJV; Tue, 1 Dec 2026 22:54:03 +0000 (UTC) From: Bart Van Assche To: Joe Perches , Andy Whitcroft Cc: Andrew Morton , linux-kernel@vger.kernel.org, Bart Van Assche Subject: [PATCH 03/10] checkpatch: cache git and PATH lookups and skip git_is_single_file() Date: Tue, 1 Dec 2026 14:53:47 -0800 Message-ID: <7c299dab9cc80bb59f34b69b686accc0073bfc5c.1796165270.git.bvanassche@acm.org> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Memoize git_commit_info() outcomes in %git_commit_info_cache while preserving ok, bad, and passthrough return semantics, skip calling git_is_single_file() when $git or $file is set or when reading from stdin ('-'), and memoize PATH lookups in which() via %which_cache. Eliminate redundant git log -1 subprocesses for repeated commit hashes (including Fixes: and commit references checked by two separate rules on the same line), stop running git ls-files on commit hashes under -g or when -f is already specified, and avoid repeating stat() scans across PAT= H. Skipping git_is_single_file() is not strictly behavior-preserving. That function runs an unquoted "git ls-files -- $filename" and matches its output against an unescaped regular expression. Hence, with this change, "checkpatch.pl -f 'a[b.c'" for a git-tracked file named 'a[b.c' no longer dies with "Unmatched [ in regex", and shell syntax errors are no longer reported for -f arguments that contain shell metacharacters. Behavior without -f, -g and '-' is unchanged. As a side effect of the caching, Perl warnings triggered inside which() (e.g. with PATH unset) or git_commit_info() are reported once per unique argument instead of once per call. Signed-off-by: Bart Van Assche --- scripts/checkpatch.pl | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 3602e79fc091..4ca3ce0f4502 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1408,16 +1408,31 @@ sub git_is_single_file { return $count eq 1 && $output =3D~ m{^${filename}$}; } =20 +my %git_commit_info_cache =3D (); + sub git_commit_info { my ($commit, $id, $desc) =3D @_; =20 return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot")); =20 + if (defined($commit) && exists($git_commit_info_cache{$commit})) { + my $cached =3D $git_commit_info_cache{$commit}; + if ($cached->[0] eq 'ok') { + return ($cached->[1], $cached->[2]); + } elsif ($cached->[0] eq 'bad') { + return (undef, $desc); + } + return ($id, $desc); + } + my $output =3D `${git_command} log --no-color --format=3D'%H %s' -1 $co= mmit 2>&1`; $output =3D~ s/^\s*//gm; my @lines =3D split("\n", $output); =20 - return ($id, $desc) if ($#lines < 0); + if ($#lines < 0) { + $git_commit_info_cache{$commit} =3D ['passthrough'] if defined($commit= ); + return ($id, $desc); + } =20 if ($lines[0] =3D~ /^error: short SHA1 $commit is ambiguous/) { # Maybe one day convert this block of bash into something that returns @@ -1429,12 +1444,15 @@ sub git_commit_info { # git log --format=3D'%H %s' -1 $line | # echo "commit $(cut -c 1-12,41-)" # done + $git_commit_info_cache{$commit} =3D ['passthrough'] if defined($commit= ); } elsif ($lines[0] =3D~ /^fatal: ambiguous argument '$commit': unknown = revision or path not in the working tree\./ || $lines[0] =3D~ /^fatal: bad object $commit/) { $id =3D undef; + $git_commit_info_cache{$commit} =3D ['bad'] if defined($commit); } else { $id =3D substr($lines[0], 0, 12); $desc =3D substr($lines[0], 41); + $git_commit_info_cache{$commit} =3D ['ok', $id, $desc] if defined($com= mit); } =20 return ($id, $desc); @@ -1483,7 +1501,7 @@ my $vname; $allow_c99_comments =3D !defined $ignore_type{"C99_COMMENT_TOLERANCE"}; for my $filename (@ARGV) { my $FILE; - my $is_git_file =3D git_is_single_file($filename); + my $is_git_file =3D (!$git && !$file && $filename ne '-') ? git_is_sing= le_file($filename) : 0; my $oldfile =3D $file; $file =3D 1 if ($is_git_file); if ($git) { @@ -1678,16 +1696,20 @@ sub same_email_addresses { $comment1 eq $comment2; } =20 +my %which_cache; + sub which { my ($bin) =3D @_; =20 + return $which_cache{$bin} if exists($which_cache{$bin}); + foreach my $path (split(/:/, $ENV{PATH})) { if (-e "$path/$bin") { - return "$path/$bin"; + return $which_cache{$bin} =3D "$path/$bin"; } } =20 - return ""; + return $which_cache{$bin} =3D ""; } =20 sub which_conf {