Messages in this thread | | | Subject | Re: [PATCH] checkpatch: Allow not using -f with files that are in git | From | Joe Perches <> | Date | Fri, 28 Aug 2020 11:17:23 -0700 |
| |
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
[]
> > +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?
Just FYI: Not really.
On my 4 year old laptop git ls-files -- <file> takes about .02 seconds.
$ time git ls-files -- 'net/l2tp/l2tp_ip.c' net/l2tp/l2tp_ip.c
real 0m0.013s user 0m0.009s sys 0m0.004s
Even uncached, it's quite quick.
# sync; echo 3 > /proc/sys/vm/drop_caches $ time git ls-files -- 'net/l2tp/l2tp_ip.c' net/l2tp/l2tp_ip.c
real 0m0.079s user 0m0.004s sys 0m0.037s
cheers, Joe
| |