checkpatch: Don't treat diffs as patches.

The patch-header cleanup code assumed that it would only ever
see patches, which was of course hogwash.  This lead to crazy
results as it tried to wrap what it thought were continuation
lines at the beginnings of raw diffs.

Signed-off-by: Gregory Bean <gbean@codeaurora.org>
This commit is contained in:
Gregory Bean
2011-10-03 10:25:39 -07:00
committed by Bryan Huntsman
parent bd58e2cc61
commit 3f66eea839
+28 -21
View File
@@ -1153,6 +1153,33 @@ sub check_absolute_file {
}
}
sub cleanup_continuation_headers {
# Collapse any header-continuation lines into a single line so they
# can be parsed meaningfully, as the parser only has one line
# of context to work with.
my $again;
do {
$again = 0;
foreach my $n (0 .. scalar(@rawlines) - 2) {
if ($rawlines[$n]=~/^\s*$/) {
# A blank line means there's no more chance
# of finding headers. Shortcut to done.
return;
}
if ($rawlines[$n]=~/^[\x21-\x39\x3b-\x7e]+:/ &&
$rawlines[$n+1]=~/^\s+/) {
# Continuation header. Collapse it.
my $line = splice @rawlines, $n+1, 1;
$line=~s/^\s+/ /;
$rawlines[$n] .= $line;
# We've 'destabilized' the list, so restart.
$again = 1;
last;
}
}
} while ($again);
}
sub process {
my $filename = shift;
@@ -1209,28 +1236,8 @@ sub process {
my $shorttext_exspc = 0;
sanitise_line_reset();
cleanup_continuation_headers();
my $line;
# Before sanitizing the rawlines, collapse any header-continuation
# lines into a single line so they can be parsed meaningfully.
my $end_of_hdrs = 0;
foreach my $rawline (@rawlines) {
if ($rawline=~/^\s*$/) {
last;
} else {
$end_of_hdrs++;
}
}
my @continuation_hdrs;
foreach my $n (0 .. $end_of_hdrs) {
if ($rawlines[$n]=~/^\s+/) {
push @continuation_hdrs, $n;
}
}
while (my $n = pop @continuation_hdrs) {
$line = splice @rawlines, $n, 1;
$line=~s/^\s+/ /;
$rawlines[$n - 1] .= $line;
}
foreach my $rawline (@rawlines) {
$linenr++;