Neaten the uses of patch/file line insertions or deletions. Hide the mechanism used.
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -1593,6 +1593,27 @@ sub fix_inserted_deleted_lines { · 1592 unmodified lines | ||
| 1593 | 1593 | return @lines; |
| 1594 | 1594 | } |
| 1595 | 1595 | |
| 1596 | +sub fix_insert_line { | |
| 1597 | + my ($linenr, $line) = @_; | |
| 1598 | + | |
| 1599 | + my $inserted = { | |
| 1600 | + LINENR => $linenr, | |
| 1601 | + LINE => $line, | |
| 1602 | + }; | |
| 1603 | + push(@fixed_inserted, $inserted); | |
| 1604 | +} | |
| 1605 | + | |
| 1606 | +sub fix_delete_line { | |
| 1607 | + my ($linenr, $line) = @_; | |
| 1608 | + | |
| 1609 | + my $deleted = { | |
| 1610 | + LINENR => $linenr, | |
| 1611 | + LINE => $line, | |
| 1612 | + }; | |
| 1613 | + | |
| 1614 | + push(@fixed_deleted, $deleted); | |
| 1615 | +} | |
| 1616 | + | |
| 1596 | 1617 | sub ERROR { |
| 1597 | 1618 | my ($type, $msg) = @_; |
| 1598 | 1619 | |
| @@ -2447,11 +2468,7 @@ sub process { · 848 unmodified lines | ||
| 2447 | 2468 | if (CHK("LINE_SPACING", |
| 2448 | 2469 | "Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) && |
| 2449 | 2470 | $fix) { |
| 2450 | − my $inserted = { | |
| 2451 | − LINENR => $fixlinenr, | |
| 2452 | − LINE => "\+", | |
| 2453 | − }; | |
| 2454 | − push(@fixed_inserted, $inserted); | |
| 2471 | + fix_insert_line($fixlinenr, "\+"); | |
| 2455 | 2472 | } |
| 2456 | 2473 | } |
| 2457 | 2474 | |
| @@ -2462,11 +2479,7 @@ sub process { · 4 unmodified lines | ||
| 2462 | 2479 | if (CHK("LINE_SPACING", |
| 2463 | 2480 | "Please don't use multiple blank lines\n" . $hereprev) && |
| 2464 | 2481 | $fix) { |
| 2465 | − my $deleted = { | |
| 2466 | − LINENR => $fixlinenr, | |
| 2467 | − LINE => $rawline, | |
| 2468 | − }; | |
| 2469 | − push(@fixed_deleted, $deleted); | |
| 2482 | + fix_delete_line($fixlinenr, $rawline); | |
| 2470 | 2483 | } |
| 2471 | 2484 | |
| 2472 | 2485 | $last_blank_line = $linenr; |
| @@ -2509,11 +2522,7 @@ sub process { · 36 unmodified lines | ||
| 2509 | 2522 | if (WARN("LINE_SPACING", |
| 2510 | 2523 | "Missing a blank line after declarations\n" . $hereprev) && |
| 2511 | 2524 | $fix) { |
| 2512 | − my $inserted = { | |
| 2513 | − LINENR => $fixlinenr, | |
| 2514 | − LINE => "\+", | |
| 2515 | − }; | |
| 2516 | − push(@fixed_inserted, $inserted); | |
| 2525 | + fix_insert_line($fixlinenr, "\+"); | |
| 2517 | 2526 | } |
| 2518 | 2527 | } |
| 2519 | 2528 | |
| @@ -2868,31 +2877,15 @@ sub process { · 348 unmodified lines | ||
| 2868 | 2877 | $prevline =~ /(?:^|[^=])=\s*$/) { |
| 2869 | 2878 | if (ERROR("OPEN_BRACE", |
| 2870 | 2879 | "that open brace { should be on the previous line\n" . $hereprev) && |
| 2871 | − $fix && $prevline =~ /^\+/) { | |
| 2872 | − my $deleted = { | |
| 2873 | − LINENR => $fixlinenr - 1, | |
| 2874 | − LINE => $prevrawline, | |
| 2875 | − }; | |
| 2876 | − push(@fixed_deleted, $deleted); | |
| 2877 | − $deleted = { | |
| 2878 | − LINENR => $fixlinenr, | |
| 2879 | − LINE => $rawline, | |
| 2880 | − }; | |
| 2881 | − push(@fixed_deleted, $deleted); | |
| 2880 | + $fix && $prevline =~ /^\+/ && $line =~ /^\+/) { | |
| 2881 | + fix_delete_line($fixlinenr - 1, $prevrawline); | |
| 2882 | + fix_delete_line($fixlinenr, $rawline); | |
| 2882 | 2883 | my $fixedline = $prevrawline; |
| 2883 | 2884 | $fixedline =~ s/\s*=\s*$/ = {/; |
| 2884 | − my $inserted = { | |
| 2885 | − LINENR => $fixlinenr, | |
| 2886 | − LINE => $fixedline, | |
| 2887 | − }; | |
| 2888 | − push(@fixed_inserted, $inserted); | |
| 2885 | + fix_insert_line($fixlinenr, $fixedline); | |
| 2889 | 2886 | $fixedline = $line; |
| 2890 | 2887 | $fixedline =~ s/^(.\s*){\s*/$1/; |
| 2891 | − $inserted = { | |
| 2892 | − LINENR => $fixlinenr, | |
| 2893 | − LINE => $fixedline, | |
| 2894 | − }; | |
| 2895 | − push(@fixed_inserted, $inserted); | |
| 2888 | + fix_insert_line($fixlinenr, $fixedline); | |
| 2896 | 2889 | } |
| 2897 | 2890 | } |
| 2898 | 2891 | |