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

Commit f2d7e4d4 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds
Browse files

checkpatch: add fix_insert_line and fix_delete_line helpers



Neaten the uses of patch/file line insertions or deletions.  Hide the
mechanism used.

Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d752fcc8
Loading
Loading
Loading
Loading
+29 −36
Original line number Original line Diff line number Diff line
@@ -1593,6 +1593,27 @@ sub fix_inserted_deleted_lines {
	return @lines;
	return @lines;
}
}


sub fix_insert_line {
	my ($linenr, $line) = @_;

	my $inserted = {
		LINENR => $linenr,
		LINE => $line,
	};
	push(@fixed_inserted, $inserted);
}

sub fix_delete_line {
	my ($linenr, $line) = @_;

	my $deleted = {
		LINENR => $linenr,
		LINE => $line,
	};

	push(@fixed_deleted, $deleted);
}

sub ERROR {
sub ERROR {
	my ($type, $msg) = @_;
	my ($type, $msg) = @_;


@@ -2447,11 +2468,7 @@ sub process {
			if (CHK("LINE_SPACING",
			if (CHK("LINE_SPACING",
				"Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) &&
				"Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) &&
			    $fix) {
			    $fix) {
			my $inserted = {
				fix_insert_line($fixlinenr, "\+");
				LINENR => $fixlinenr,
				LINE => "\+",
			};
			push(@fixed_inserted, $inserted);
			}
			}
		}
		}


@@ -2462,11 +2479,7 @@ sub process {
			if (CHK("LINE_SPACING",
			if (CHK("LINE_SPACING",
				"Please don't use multiple blank lines\n" . $hereprev) &&
				"Please don't use multiple blank lines\n" . $hereprev) &&
			    $fix) {
			    $fix) {
			my $deleted = {
				fix_delete_line($fixlinenr, $rawline);
				LINENR => $fixlinenr,
				LINE => $rawline,
			};
			push(@fixed_deleted, $deleted);
			}
			}


			$last_blank_line = $linenr;
			$last_blank_line = $linenr;
@@ -2509,11 +2522,7 @@ sub process {
			if (WARN("LINE_SPACING",
			if (WARN("LINE_SPACING",
				 "Missing a blank line after declarations\n" . $hereprev) &&
				 "Missing a blank line after declarations\n" . $hereprev) &&
			    $fix) {
			    $fix) {
			my $inserted = {
				fix_insert_line($fixlinenr, "\+");
				LINENR => $fixlinenr,
				LINE => "\+",
			};
			push(@fixed_inserted, $inserted);
			}
			}
		}
		}


@@ -2868,31 +2877,15 @@ sub process {
		    $prevline =~ /(?:^|[^=])=\s*$/) {
		    $prevline =~ /(?:^|[^=])=\s*$/) {
			if (ERROR("OPEN_BRACE",
			if (ERROR("OPEN_BRACE",
				  "that open brace { should be on the previous line\n" . $hereprev) &&
				  "that open brace { should be on the previous line\n" . $hereprev) &&
			    $fix && $prevline =~ /^\+/) {
			    $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
				my $deleted = {
				fix_delete_line($fixlinenr - 1, $prevrawline);
					LINENR => $fixlinenr - 1,
				fix_delete_line($fixlinenr, $rawline);
					LINE => $prevrawline,
				};
				push(@fixed_deleted, $deleted);
				$deleted = {
					LINENR => $fixlinenr,
					LINE => $rawline,
				};
				push(@fixed_deleted, $deleted);
				my $fixedline = $prevrawline;
				my $fixedline = $prevrawline;
				$fixedline =~ s/\s*=\s*$/ = {/;
				$fixedline =~ s/\s*=\s*$/ = {/;
				my $inserted = {
				fix_insert_line($fixlinenr, $fixedline);
					LINENR => $fixlinenr,
					LINE => $fixedline,
				};
				push(@fixed_inserted, $inserted);
				$fixedline = $line;
				$fixedline = $line;
				$fixedline =~ s/^(.\s*){\s*/$1/;
				$fixedline =~ s/^(.\s*){\s*/$1/;
				$inserted = {
				fix_insert_line($fixlinenr, $fixedline);
					LINENR => $fixlinenr,
					LINE => $fixedline,
				};
				push(@fixed_inserted, $inserted);
			}
			}
		}
		}