Re: [PATCH] checkpatch: Allow not using -f with files that are in git
From: Joe Perches
Date: Fri Aug 28 2020 - 04:04:15 EST
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.