Commit 34d8815f authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

checkpatch: add --showfile to allow input via pipe to show filenames

Using "git diff | ./scripts/checkpatch -" does not have an
easy mechanism to see the files and lines actually modified.

Add --showfile to see the file and line specified in the diff.

When --showfile is used without --terse, the second line of each
message output is redundant, so it is removed.
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Cc: Petr Mladek <pmladek@suse.cz>
Cc: Andy Whitcroft <apw@canonical.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 57230297
...@@ -25,6 +25,7 @@ my $chk_patch = 1; ...@@ -25,6 +25,7 @@ my $chk_patch = 1;
my $tst_only; my $tst_only;
my $emacs = 0; my $emacs = 0;
my $terse = 0; my $terse = 0;
my $showfile = 0;
my $file = 0; my $file = 0;
my $check = 0; my $check = 0;
my $check_orig = 0; my $check_orig = 0;
...@@ -66,6 +67,7 @@ Options: ...@@ -66,6 +67,7 @@ Options:
--patch treat FILE as patchfile (default) --patch treat FILE as patchfile (default)
--emacs emacs compile window format --emacs emacs compile window format
--terse one line per report --terse one line per report
--showfile emit diffed file position, not input file position
-f, --file treat FILE as regular source file -f, --file treat FILE as regular source file
--subjective, --strict enable more subjective tests --subjective, --strict enable more subjective tests
--types TYPE(,TYPE2...) show only these comma separated message types --types TYPE(,TYPE2...) show only these comma separated message types
...@@ -137,6 +139,7 @@ GetOptions( ...@@ -137,6 +139,7 @@ GetOptions(
'patch!' => \$chk_patch, 'patch!' => \$chk_patch,
'emacs!' => \$emacs, 'emacs!' => \$emacs,
'terse!' => \$terse, 'terse!' => \$terse,
'showfile!' => \$showfile,
'f|file!' => \$file, 'f|file!' => \$file,
'subjective!' => \$check, 'subjective!' => \$check,
'strict!' => \$check, 'strict!' => \$check,
...@@ -1693,6 +1696,12 @@ sub report { ...@@ -1693,6 +1696,12 @@ sub report {
} }
$output .= RESET if (-t STDOUT && $color); $output .= RESET if (-t STDOUT && $color);
$output .= ' ' . $msg . "\n"; $output .= ' ' . $msg . "\n";
if ($showfile) {
my @lines = split("\n", $output, -1);
splice(@lines, 1, 1);
$output = join("\n", @lines);
}
$output = (split('\n', $output))[0] . "\n" if ($terse); $output = (split('\n', $output))[0] . "\n" if ($terse);
push(our @report, $output); push(our @report, $output);
...@@ -2119,10 +2128,6 @@ sub process { ...@@ -2119,10 +2128,6 @@ sub process {
my $hunk_line = ($realcnt != 0); my $hunk_line = ($realcnt != 0);
#make up the handle for any error we report on this line
$prefix = "$filename:$realline: " if ($emacs && $file);
$prefix = "$filename:$linenr: " if ($emacs && !$file);
$here = "#$linenr: " if (!$file); $here = "#$linenr: " if (!$file);
$here = "#$realline: " if ($file); $here = "#$realline: " if ($file);
...@@ -2152,6 +2157,13 @@ sub process { ...@@ -2152,6 +2157,13 @@ sub process {
$found_file = 1; $found_file = 1;
} }
#make up the handle for any error we report on this line
if ($showfile) {
$prefix = "$realfile:$realline: "
} elsif ($emacs) {
$prefix = "$filename:$linenr: ";
}
if ($found_file) { if ($found_file) {
if ($realfile =~ m@^(drivers/net/|net/)@) { if ($realfile =~ m@^(drivers/net/|net/)@) {
$check = 1; $check = 1;
...@@ -5606,7 +5618,7 @@ sub process { ...@@ -5606,7 +5618,7 @@ sub process {
ERROR("NOT_UNIFIED_DIFF", ERROR("NOT_UNIFIED_DIFF",
"Does not appear to be a unified-diff format patch\n"); "Does not appear to be a unified-diff format patch\n");
} }
if ($is_patch && $chk_signoff && $signoff == 0) { if ($is_patch && $filename ne '-' && $chk_signoff && $signoff == 0) {
ERROR("MISSING_SIGN_OFF", ERROR("MISSING_SIGN_OFF",
"Missing Signed-off-by: line(s)\n"); "Missing Signed-off-by: line(s)\n");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment