* [PATCH] scripts/checkpatch.pl: add a check for the patch level (patch -p<num>) @ 2007-12-17 7:11 Borislav Petkov 2007-12-18 5:46 ` Borislav Petkov 0 siblings, 1 reply; 4+ messages in thread From: Borislav Petkov @ 2007-12-17 7:11 UTC (permalink / raw) To: apw, rdunlap, jschopp; +Cc: linux-kernel Being bitten by this several times myself here's a quick hack for checking the patch level of the diffs in a patch file. It works only when checkpatch.pl is called from within the kernel tree. --- Signed-off-by: Borislav Petkov <bbpetkov@yahoo.de> -- scripts/checkpatch.pl | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 579f50f..b1329fc 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -653,6 +653,18 @@ sub CHK { } } +sub check_patchlevel { + + my ($path) = @_; + $path =~ s![^/]*/!!; + + if ($tree) { + if (!stat($path)) { + WARN("Check the patchlevel (hint: patch option -p)"); + } + } +} + sub process { my $filename = shift; my @lines = @_; @@ -713,10 +725,16 @@ sub process { #extract the filename as it passes if ($line=~/^\+\+\+\s+(\S+)/) { $realfile=$1; + + if ($realfile) { + check_patchlevel($realfile); + } + $realfile =~ s@^[^/]*/@@; $in_comment = 0; next; } + #extract the line range in the file after the patch is applied if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { $is_patch = 1; -- Regards/Gruß, Boris. ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] scripts/checkpatch.pl: add a check for the patch level (patch -p<num>) 2007-12-17 7:11 [PATCH] scripts/checkpatch.pl: add a check for the patch level (patch -p<num>) Borislav Petkov @ 2007-12-18 5:46 ` Borislav Petkov 2007-12-21 18:12 ` Andy Whitcroft 0 siblings, 1 reply; 4+ messages in thread From: Borislav Petkov @ 2007-12-18 5:46 UTC (permalink / raw) To: apw, rdunlap, jschopp, linux-kernel; +Cc: Andrew Morton On Mon, Dec 17, 2007 at 08:11:05AM +0100, Borislav Petkov wrote: A slightly microoptimized version 1.1: --- From: Borislav Petkov <bbpetkov@yahoo.de> Check the patch level of the single hunks in a patch file, however only when checkpatch.pl is called from within the kernel tree. Signed-off-by: Borislav Petkov <bbpetkov@yahoo.de> -- diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 579f50f..3eda27b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -653,6 +653,18 @@ sub CHK { } } +sub check_patchlevel { + + if ($tree) { + my ($path) = @_; + $path =~ s![^/]*/!!; + + if (!stat($path)) { + WARN("Check the patchlevel (hint: patch option -p)"); + } + } +} + sub process { my $filename = shift; my @lines = @_; @@ -713,10 +725,16 @@ sub process { #extract the filename as it passes if ($line=~/^\+\+\+\s+(\S+)/) { $realfile=$1; + + if ($realfile) { + check_patchlevel($realfile); + } + $realfile =~ s@^[^/]*/@@; $in_comment = 0; next; } + #extract the line range in the file after the patch is applied if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { $is_patch = 1; -- Regards/Gruß, Boris. ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] scripts/checkpatch.pl: add a check for the patch level (patch -p<num>) 2007-12-18 5:46 ` Borislav Petkov @ 2007-12-21 18:12 ` Andy Whitcroft 2007-12-23 7:52 ` Borislav Petkov 0 siblings, 1 reply; 4+ messages in thread From: Andy Whitcroft @ 2007-12-21 18:12 UTC (permalink / raw) To: bbpetkov, rdunlap, jschopp, linux-kernel, Andrew Morton On Tue, Dec 18, 2007 at 06:46:41AM +0100, Borislav Petkov wrote: > On Mon, Dec 17, 2007 at 08:11:05AM +0100, Borislav Petkov wrote: > > A slightly microoptimized version 1.1: > > --- > From: Borislav Petkov <bbpetkov@yahoo.de> > > > Check the patch level of the single hunks in a patch file, however only when > checkpatch.pl is called from within the kernel tree. > > Signed-off-by: Borislav Petkov <bbpetkov@yahoo.de> > -- > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 579f50f..3eda27b 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -653,6 +653,18 @@ sub CHK { > } > } > > +sub check_patchlevel { > + > + if ($tree) { > + my ($path) = @_; > + $path =~ s![^/]*/!!; > + > + if (!stat($path)) { > + WARN("Check the patchlevel (hint: patch option -p)"); > + } > + } Hmmm that will trigger on all patches which create new files if I am grokking you correctly. I would have thought this would pretty easy to check from the form of the names. Hmmm. > +} > + > sub process { > my $filename = shift; > my @lines = @_; > @@ -713,10 +725,16 @@ sub process { > #extract the filename as it passes > if ($line=~/^\+\+\+\s+(\S+)/) { > $realfile=$1; > + > + if ($realfile) { > + check_patchlevel($realfile); > + } > + > $realfile =~ s@^[^/]*/@@; > $in_comment = 0; > next; > } > + > #extract the line range in the file after the patch is applied > if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { > $is_patch = 1; -apw ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scripts/checkpatch.pl: add a check for the patch level (patch -p<num>) 2007-12-21 18:12 ` Andy Whitcroft @ 2007-12-23 7:52 ` Borislav Petkov 0 siblings, 0 replies; 4+ messages in thread From: Borislav Petkov @ 2007-12-23 7:52 UTC (permalink / raw) To: Andy Whitcroft; +Cc: rdunlap, jschopp, linux-kernel, Andrew Morton On Fri, Dec 21, 2007 at 06:12:02PM +0000, Andy Whitcroft wrote: > On Tue, Dec 18, 2007 at 06:46:41AM +0100, Borislav Petkov wrote: > > On Mon, Dec 17, 2007 at 08:11:05AM +0100, Borislav Petkov wrote: > > > > A slightly microoptimized version 1.1: > > > > --- > > From: Borislav Petkov <bbpetkov@yahoo.de> > > > > > > Check the patch level of the single hunks in a patch file, however only when > > checkpatch.pl is called from within the kernel tree. > > > > Signed-off-by: Borislav Petkov <bbpetkov@yahoo.de> > > -- > > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > > index 579f50f..3eda27b 100755 > > --- a/scripts/checkpatch.pl > > +++ b/scripts/checkpatch.pl > > @@ -653,6 +653,18 @@ sub CHK { > > } > > } > > > > +sub check_patchlevel { > > + > > + if ($tree) { > > + my ($path) = @_; > > + $path =~ s![^/]*/!!; > > + > > + if (!stat($path)) { > > + WARN("Check the patchlevel (hint: patch option -p)"); > > + } > > + } > > Hmmm that will trigger on all patches which create new files if I am > grokking you correctly. > > I would have thought this would pretty easy to check from the form of > the names. Hmmm. Yep, I thought that too. Still, this way of checking the patch level using the relative file pathname in the kernel tree seemed pretty straightforward so i sent it. Off the top of my head, we could check for "/dev/null" on the "---" line and skip that hunk... like so: --- From: Borislav Petkov <bbpetkov@yahoo.de> Check the patch level of the diff hunks in a patch text file. It works only when checkpatch.pl is called from within the kernel tree. The only case it misses is when the patch creates a new file and the patchlevel is wrong. However, this cannot be checked for reliably using this approach of stat()ing the relative url of the patched file. scripts/checkpatch.pl | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 579f50f..0fe80fb 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -653,6 +653,22 @@ sub CHK { } } +sub check_patchlevel { + + if ($tree) { + my ($path, $prev) = @_; + +# don't do any checking if it's a newly created file + return if $prev =~ m!/dev/null!; + + $path =~ s![^/]*/!!; + + if (!stat($path)) { + WARN("Check the patchlevel (hint: patch option -p)"); + } + } +} + sub process { my $filename = shift; my @lines = @_; @@ -713,10 +729,16 @@ sub process { #extract the filename as it passes if ($line=~/^\+\+\+\s+(\S+)/) { $realfile=$1; + + if ($realfile) { + check_patchlevel($realfile, $lines[$linenr-2]); + } + $realfile =~ s@^[^/]*/@@; $in_comment = 0; next; } + #extract the line range in the file after the patch is applied if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { $is_patch = 1; -- Regards/Gruß, Boris. ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-12-23 7:54 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2007-12-17 7:11 [PATCH] scripts/checkpatch.pl: add a check for the patch level (patch -p<num>) Borislav Petkov 2007-12-18 5:46 ` Borislav Petkov 2007-12-21 18:12 ` Andy Whitcroft 2007-12-23 7:52 ` Borislav Petkov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox