scripts/checkpatch.pl: add a check for the patch level (patch -p<num>)
PATCH 1/1 scripts/checkpatch.pl: add a check for the patch level (patch -p<num>)
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.
---
--
scripts/checkpatch.pl | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +18 -0
@@ -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;
Signature · 2 lines
Regards/Gruß,
Boris.On Mon, Dec 17, 2007 at 08:11:05AM +0100, Borislav Petkov wrote:
A slightly microoptimized version 1.1:
---
From: Borislav Petkov <[email protected]>
Check the patch level of the single hunks in a patch file, however only when checkpatch.pl is called from within the kernel tree.
--
scripts/checkpatch.pl +18 -0
@@ -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;
Signature · 2 lines
Regards/Gruß,
Boris.Quoted 22 lines · Borislav Petkov
On Mon, Dec 17, 2007 at 08:11:05AM +0100, Borislav Petkov wrote:
A slightly microoptimized version 1.1:
---
From: Borislav Petkov <[email protected]>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 <[email protected]>--
scripts/checkpatch.pl +0
-0@@ -653,6 +653,18 @@ sub CHK { } }
scripts/checkpatch.pl sub CHK { · line 665
Quoted 10 lines
scripts/checkpatch.pl +10
-0+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.
Quoted 12 lines
scripts/checkpatch.pl +5
-0+} + 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);
scripts/checkpatch.pl sub process { · line 740
Quoted 10 lines
scripts/checkpatch.pl +3
-0+ } + $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
Quoted 37 lines · Andy Whitcroft
Quoted 22 lines · Borislav Petkov
On Mon, Dec 17, 2007 at 08:11:05AM +0100, Borislav Petkov wrote:
A slightly microoptimized version 1.1:
---
From: Borislav Petkov <[email protected]>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 <[email protected]>--
scripts/checkpatch.pl +0
-0@@ -653,6 +653,18 @@ sub CHK { } }scripts/checkpatch.pl sub CHK { · line 665
Quoted 10 lines
scripts/checkpatch.pl +10
-0+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.
Quoted 2 lines
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 <[email protected]>
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(-)
scripts/checkpatch.pl +22 -0
@@ -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;
Signature · 2 lines
Regards/Gruß,
Boris.