From 3f66eea8397fc777f0b4b23da365350fc0cbcbd0 Mon Sep 17 00:00:00 2001 From: Gregory Bean Date: Tue, 19 Jul 2011 16:37:49 -0700 Subject: [PATCH] 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 --- scripts/checkpatch.pl | 49 ++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 2d4ce154401..1163275a8d4 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -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++;