diff options
author | Joe Perches <joe@perches.com> | 2015-06-25 18:03:05 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-25 20:00:41 -0400 |
commit | 34d8815f9512b01757e08f8101730503c87b6353 (patch) | |
tree | 1eaf8b5eff118453386622d2137c5120e5ff4c50 /scripts | |
parent | 57230297116faf5b0a995916d5dd5fedab54cba3 (diff) |
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: Joe Perches <joe@perches.com>
Cc: Petr Mladek <pmladek@suse.cz>
Cc: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d52293f65374..46ebc6a0fa58 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -25,6 +25,7 @@ my $chk_patch = 1; | |||
25 | my $tst_only; | 25 | my $tst_only; |
26 | my $emacs = 0; | 26 | my $emacs = 0; |
27 | my $terse = 0; | 27 | my $terse = 0; |
28 | my $showfile = 0; | ||
28 | my $file = 0; | 29 | my $file = 0; |
29 | my $check = 0; | 30 | my $check = 0; |
30 | my $check_orig = 0; | 31 | my $check_orig = 0; |
@@ -66,6 +67,7 @@ Options: | |||
66 | --patch treat FILE as patchfile (default) | 67 | --patch treat FILE as patchfile (default) |
67 | --emacs emacs compile window format | 68 | --emacs emacs compile window format |
68 | --terse one line per report | 69 | --terse one line per report |
70 | --showfile emit diffed file position, not input file position | ||
69 | -f, --file treat FILE as regular source file | 71 | -f, --file treat FILE as regular source file |
70 | --subjective, --strict enable more subjective tests | 72 | --subjective, --strict enable more subjective tests |
71 | --types TYPE(,TYPE2...) show only these comma separated message types | 73 | --types TYPE(,TYPE2...) show only these comma separated message types |
@@ -137,6 +139,7 @@ GetOptions( | |||
137 | 'patch!' => \$chk_patch, | 139 | 'patch!' => \$chk_patch, |
138 | 'emacs!' => \$emacs, | 140 | 'emacs!' => \$emacs, |
139 | 'terse!' => \$terse, | 141 | 'terse!' => \$terse, |
142 | 'showfile!' => \$showfile, | ||
140 | 'f|file!' => \$file, | 143 | 'f|file!' => \$file, |
141 | 'subjective!' => \$check, | 144 | 'subjective!' => \$check, |
142 | 'strict!' => \$check, | 145 | 'strict!' => \$check, |
@@ -1693,6 +1696,12 @@ sub report { | |||
1693 | } | 1696 | } |
1694 | $output .= RESET if (-t STDOUT && $color); | 1697 | $output .= RESET if (-t STDOUT && $color); |
1695 | $output .= ' ' . $msg . "\n"; | 1698 | $output .= ' ' . $msg . "\n"; |
1699 | |||
1700 | if ($showfile) { | ||
1701 | my @lines = split("\n", $output, -1); | ||
1702 | splice(@lines, 1, 1); | ||
1703 | $output = join("\n", @lines); | ||
1704 | } | ||
1696 | $output = (split('\n', $output))[0] . "\n" if ($terse); | 1705 | $output = (split('\n', $output))[0] . "\n" if ($terse); |
1697 | 1706 | ||
1698 | push(our @report, $output); | 1707 | push(our @report, $output); |
@@ -2119,10 +2128,6 @@ sub process { | |||
2119 | 2128 | ||
2120 | my $hunk_line = ($realcnt != 0); | 2129 | my $hunk_line = ($realcnt != 0); |
2121 | 2130 | ||
2122 | #make up the handle for any error we report on this line | ||
2123 | $prefix = "$filename:$realline: " if ($emacs && $file); | ||
2124 | $prefix = "$filename:$linenr: " if ($emacs && !$file); | ||
2125 | |||
2126 | $here = "#$linenr: " if (!$file); | 2131 | $here = "#$linenr: " if (!$file); |
2127 | $here = "#$realline: " if ($file); | 2132 | $here = "#$realline: " if ($file); |
2128 | 2133 | ||
@@ -2152,6 +2157,13 @@ sub process { | |||
2152 | $found_file = 1; | 2157 | $found_file = 1; |
2153 | } | 2158 | } |
2154 | 2159 | ||
2160 | #make up the handle for any error we report on this line | ||
2161 | if ($showfile) { | ||
2162 | $prefix = "$realfile:$realline: " | ||
2163 | } elsif ($emacs) { | ||
2164 | $prefix = "$filename:$linenr: "; | ||
2165 | } | ||
2166 | |||
2155 | if ($found_file) { | 2167 | if ($found_file) { |
2156 | if ($realfile =~ m@^(drivers/net/|net/)@) { | 2168 | if ($realfile =~ m@^(drivers/net/|net/)@) { |
2157 | $check = 1; | 2169 | $check = 1; |
@@ -5606,7 +5618,7 @@ sub process { | |||
5606 | ERROR("NOT_UNIFIED_DIFF", | 5618 | ERROR("NOT_UNIFIED_DIFF", |
5607 | "Does not appear to be a unified-diff format patch\n"); | 5619 | "Does not appear to be a unified-diff format patch\n"); |
5608 | } | 5620 | } |
5609 | if ($is_patch && $chk_signoff && $signoff == 0) { | 5621 | if ($is_patch && $filename ne '-' && $chk_signoff && $signoff == 0) { |
5610 | ERROR("MISSING_SIGN_OFF", | 5622 | ERROR("MISSING_SIGN_OFF", |
5611 | "Missing Signed-off-by: line(s)\n"); | 5623 | "Missing Signed-off-by: line(s)\n"); |
5612 | } | 5624 | } |