Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d5df1b8 authored by Gregory Bean's avatar Gregory Bean Committed by Gerrit - the friendly Code Review server
Browse files

checkpatch: Merge continuation-header handling from .38



This commit is a cherry pick and squash of commits:
85c2ee62d37c19456c6dc83db262123956f010ac
4bc7c6001daba7d4037f54f67bae7fa90f759402

  checkpatch: Handle continuation headers.

  Continuation headers baffle checkpatch, as it can only operate
  on one line of context at a time.  When continuation headers are found,
  put them up with the header they're continuing so the whole thing
  can be parsed in a single line of context.

  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.

Change-Id: I2d22ed056f8203ae6dae473b01ae66bc1963ae75
Signed-off-by: default avatarGregory Bean <gbean@codeaurora.org>
Signed-off-by: default avatarRishabh Bhatnagar <rishabhb@codeaurora.org>
parent b31fc5d2
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -2196,6 +2196,33 @@ sub tabify {
	return "$leading";
}

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 pos_last_openparen {
	my ($line) = @_;

@@ -2298,7 +2325,9 @@ sub process {
	my $checklicenseline = 1;

	sanitise_line_reset();
	cleanup_continuation_headers();
	my $line;

	foreach my $rawline (@rawlines) {
		$linenr++;
		$line = $rawline;