[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <bb42e56210148307bd7eaaf3da1823ce04a9849b.camel@perches.com>
Date: Fri, 28 Aug 2020 01:03:55 -0700
From: Joe Perches <joe@...ches.com>
To: Rasmus Villemoes <linux@...musvillemoes.dk>,
Andrew Morton <akpm@...ux-foundation.org>
Cc: Andy Whitcroft <apw@...dowen.org>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] checkpatch: Allow not using -f with files that are in
git
On Tue, 2020-08-25 at 14:23 +0200, Rasmus Villemoes wrote:
> On 25/08/2020 02.09, 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.
>
> Heh, I read the patch subject to mean you introduced a way for subsystem
> maintainers to prevent running checkpatch -f on their files, which I
> think some would like ;)
>
> > 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}$};
> > +}
>
> Isn't that somewhat expensive to do for each file? Why not postpone that
> check till we're about to complain that the file is not a diff (haven't
> looked at how such a refactoring would look).
It's necessary because you need the --file option set _before_
analyzing the file content.
Oddly, I didn't receive this email directly so I couldn't reply
to it earlier.
Powered by blists - more mailing lists