diff options
author | Joe Perches <joe@perches.com> | 2015-06-25 18:03:27 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-25 20:00:42 -0400 |
commit | e518e9a59ec37a323b0f4785e2311a1ec1433c6d (patch) | |
tree | 854f8e6f053b56d06a071dc129732c989f74317e /scripts/checkpatch.pl | |
parent | 5a6d20ce19b770c9946281783614294b3f570ab8 (diff) |
checkpatch: emit an error when there's a diff in a changelog
People often put diff snippets in changelogs. This causes problems
when one tries to apply a file containing both the changelog and the
diff because patch(1) tries to apply the diff which it found in the
changelog.
Warn once when what seems to be a diff snippet in the changelog exists.
Signed-off-by: Joe Perches <joe@perches.com>
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 4cf4473ebf17..daf466d26a4b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -1954,6 +1954,7 @@ sub process { | |||
1954 | my $in_header_lines = $file ? 0 : 1; | 1954 | my $in_header_lines = $file ? 0 : 1; |
1955 | my $in_commit_log = 0; #Scanning lines before patch | 1955 | my $in_commit_log = 0; #Scanning lines before patch |
1956 | my $commit_log_long_line = 0; | 1956 | my $commit_log_long_line = 0; |
1957 | my $commit_log_has_diff = 0; | ||
1957 | my $reported_maintainer_file = 0; | 1958 | my $reported_maintainer_file = 0; |
1958 | my $non_utf8_charset = 0; | 1959 | my $non_utf8_charset = 0; |
1959 | 1960 | ||
@@ -2087,7 +2088,8 @@ sub process { | |||
2087 | my $rawline = $rawlines[$linenr - 1]; | 2088 | my $rawline = $rawlines[$linenr - 1]; |
2088 | 2089 | ||
2089 | #extract the line range in the file after the patch is applied | 2090 | #extract the line range in the file after the patch is applied |
2090 | if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { | 2091 | if (!$in_commit_log && |
2092 | $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { | ||
2091 | $is_patch = 1; | 2093 | $is_patch = 1; |
2092 | $first_line = $linenr + 1; | 2094 | $first_line = $linenr + 1; |
2093 | $realline=$1-1; | 2095 | $realline=$1-1; |
@@ -2181,6 +2183,17 @@ sub process { | |||
2181 | 2183 | ||
2182 | $cnt_lines++ if ($realcnt != 0); | 2184 | $cnt_lines++ if ($realcnt != 0); |
2183 | 2185 | ||
2186 | # Check if the commit log has what seems like a diff which can confuse patch | ||
2187 | if ($in_commit_log && !$commit_log_has_diff && | ||
2188 | (($line =~ m@^\s+diff\b.*a/[\w/]+@ && | ||
2189 | $line =~ m@^\s+diff\b.*a/([\w/]+)\s+b/$1\b@) || | ||
2190 | $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ || | ||
2191 | $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) { | ||
2192 | ERROR("DIFF_IN_COMMIT_MSG", | ||
2193 | "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr); | ||
2194 | $commit_log_has_diff = 1; | ||
2195 | } | ||
2196 | |||
2184 | # Check for incorrect file permissions | 2197 | # Check for incorrect file permissions |
2185 | if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) { | 2198 | if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) { |
2186 | my $permhere = $here . "FILE: $realfile\n"; | 2199 | my $permhere = $here . "FILE: $realfile\n"; |