From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9309FC43461 for ; Sun, 13 Sep 2020 04:02:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 578682184D for ; Sun, 13 Sep 2020 04:02:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725928AbgIMECj (ORCPT ); Sun, 13 Sep 2020 00:02:39 -0400 Received: from smtprelay0179.hostedemail.com ([216.40.44.179]:52530 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725894AbgIMECg (ORCPT ); Sun, 13 Sep 2020 00:02:36 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay05.hostedemail.com (Postfix) with ESMTP id 2FC6318021449; Sun, 13 Sep 2020 04:02:35 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: nest51_301658d270fc X-Filterd-Recvd-Size: 2568 Received: from XPS-9350 (unknown [172.58.44.91]) (Authenticated sender: joe@perches.com) by omf02.hostedemail.com (Postfix) with ESMTPA; Sun, 13 Sep 2020 04:02:33 +0000 (UTC) Message-ID: Subject: Re: [PATCH] checkpatch: Allow not using -f with files that are in git From: Joe Perches To: Andrew Morton Cc: Andy Whitcroft , LKML Date: Sat, 12 Sep 2020 21:02:30 -0700 In-Reply-To: <45b81a48e1568bd0126a96f5046eb7aaae9b83c9.camel@perches.com> References: <45b81a48e1568bd0126a96f5046eb7aaae9b83c9.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.36.4-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2020-08-24 at 17:09 -0700, Joe Perches wrote: > 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. Andrew? ping? > Signed-off-by: Joe Perches > --- > scripts/checkpatch.pl | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 79fc357b18cd..cdee7cfadc11 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -976,6 +976,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`; > + my $count = $output =~ tr/\n//; > + return $count eq 1 && $output =~ m{^${filename}$}; > +} > + > sub git_commit_info { > my ($commit, $id, $desc) = @_; > > @@ -1049,6 +1059,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"; > @@ -1093,6 +1106,7 @@ for my $filename (@ARGV) { > @modifierListFile = (); > @typeListFile = (); > build_types(); > + $file = $oldfile if ($is_git_file); > } > > if (!$quiet) { >