From patchwork Fri Oct 16 02:49:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11840761 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB24D15E6 for ; Fri, 16 Oct 2020 02:49:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A02722087D for ; Fri, 16 Oct 2020 02:49:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="jd0J4+ga" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A02722087D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8B3B8940066; Thu, 15 Oct 2020 22:49:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 83DDE940034; Thu, 15 Oct 2020 22:49:07 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DDCF940066; Thu, 15 Oct 2020 22:49:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0197.hostedemail.com [216.40.44.197]) by kanga.kvack.org (Postfix) with ESMTP id 3E568940034 for ; Thu, 15 Oct 2020 22:49:07 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DCD86180AD807 for ; Fri, 16 Oct 2020 02:49:06 +0000 (UTC) X-FDA: 77376256692.13.shade21_1b1273227219 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id BA37D18140B67 for ; Fri, 16 Oct 2020 02:49:06 +0000 (UTC) X-Spam-Summary: 1,0,0,25ff3f74aeef4905,d41d8cd98f00b204,akpm@linux-foundation.org,,RULES_HIT:41:355:379:800:960:967:973:982:988:989:1260:1345:1359:1381:1431:1437:1534:1542:1711:1730:1747:1777:1792:2393:2525:2559:2564:2682:2685:2693:2859:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3653:3865:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:5007:6261:6299:6653:7576:7903:8957:9025:9163:9545:10004:11026:11473:11658:11914:12043:12048:12297:12438:12517:12519:12555:12679:13846:14181:14721:21063:21080:21451:21627:21939:21990:30054:30070:30080,0,RBL:198.145.29.99:@linux-foundation.org:.lbl8.mailshell.net-62.2.0.100 64.100.201.201;04ygpcby6upxe5796om69sor6orozypzmjgixxd1nz4neif55sjbqus1ctfg3sw.8wnzd66fmiksueaq7scwpu8eexsxgmbw7oxre3gwdz49rb9ro3z5fzrteigffa1.e-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:2 3,LUA_SU X-HE-Tag: shade21_1b1273227219 X-Filterd-Recvd-Size: 3445 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Fri, 16 Oct 2020 02:49:06 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 165532087D; Fri, 16 Oct 2020 02:49:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602816545; bh=Zxzn8PL71kIv6dLENtKIJvNvYh8RH+hFuUcP38yDvvI=; h=Date:From:To:Subject:In-Reply-To:From; b=jd0J4+gavYfNf9Gurx1LRf+7EPuQ4urd3DvU6imUC9CzDZR82zxGenWogW12wWhpi bZ6smOIdyQCRfvZnk0w9HPMdjv7N0mwN14LBwF4oRsicYIbomwgbc1LETSwwxW59Y8 /cVksjlUZUym8goRDRZDMvfguSC5r8H/Dd2OqjQw= Date: Thu, 15 Oct 2020 19:49:04 -0700 From: Andrew Morton To: akpm@linux-foundation.org, joe@perches.com, julia.lawall@inria.fr, linux-mm@kvack.org, linux@rasmusvillemoes.dk, mm-commits@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 128/156] checkpatch: allow not using -f with files that are in git Message-ID: <20201016024904.klsWPnHIM%akpm@linux-foundation.org> In-Reply-To: <20201015192732.f448da14e9854c7cb7299956@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Joe Perches Subject: checkpatch: allow not using -f with files that are in git If a file exists in git and checkpatch is used without the -f flag for scanning a file, then checkpatch will scan the file assuming it's a patch and emit: ERROR: Does not appear to be a unified-diff format patch Change the behavior to assume the -f flag if the file exists in git. [joe@perches.com: fix git "fatal" warning if file argument outside kernel tree] Link: https://lkml.kernel.org/r/b6afa04112d450c2fc120a308d706acd60cee294.camel@perches.com Link: https://lkml.kernel.org/r/45b81a48e1568bd0126a96f5046eb7aaae9b83c9.camel@perches.com Signed-off-by: Joe Perches Reviewed-by: Julia Lawall Cc: Rasmus Villemoes Signed-off-by: Andrew Morton --- scripts/checkpatch.pl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) --- a/scripts/checkpatch.pl~checkpatch-allow-not-using-f-with-files-that-are-in-git +++ a/scripts/checkpatch.pl @@ -974,6 +974,16 @@ sub seed_camelcase_includes { } } +sub git_is_single_file { + my ($filename) = @_; + + return 0 if ((which("git") eq "") || !(-e "$gitroot")); + + my $output = `${git_command} ls-files -- $filename 2>/dev/null`; + my $count = $output =~ tr/\n//; + return $count eq 1 && $output =~ m{^${filename}$}; +} + sub git_commit_info { my ($commit, $id, $desc) = @_; @@ -1047,6 +1057,9 @@ my $vname; $allow_c99_comments = !defined $ignore_type{"C99_COMMENT_TOLERANCE"}; for my $filename (@ARGV) { my $FILE; + my $is_git_file = git_is_single_file($filename); + my $oldfile = $file; + $file = 1 if ($is_git_file); if ($git) { open($FILE, '-|', "git format-patch -M --stdout -1 $filename") || die "$P: $filename: git format-patch failed - $!\n"; @@ -1091,6 +1104,7 @@ for my $filename (@ARGV) { @modifierListFile = (); @typeListFile = (); build_types(); + $file = $oldfile if ($is_git_file); } if (!$quiet) {