summaryrefslogtreecommitdiff
path: root/rc
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2024-01-22 06:58:20 +0100
committerJohannes Altmanninger <aclopte@gmail.com>2024-01-22 07:02:31 +0100
commit1276e67ef720b19bfe5354495ae72e08c00226ee (patch)
tree9723130824d28a318c58712ad45ec6181822ef3d /rc
parent869e89b3e5f05acb213d04ea496a0c22c86d90bc (diff)
rc tools patch: skip spurious diff header for files with no changes
Since :patch transforms its inputs into context-only lines, we can easily get into a state where a file diff has only context lines. git apply does not accept a "diff" without any hunk, so let's skip that.
Diffstat (limited to 'rc')
-rwxr-xr-xrc/tools/patch-range.pl8
1 files changed, 7 insertions, 1 deletions
diff --git a/rc/tools/patch-range.pl b/rc/tools/patch-range.pl
index 10cc74f4..b3c3dc91 100755
--- a/rc/tools/patch-range.pl
+++ b/rc/tools/patch-range.pl
@@ -18,6 +18,7 @@ my $reverse = grep /^(--reverse|-R)$/, @ARGV;
my $lineno = 0;
my $original = "";
+my $diff_header = "";
my $wheat = "";
my $chaff = "";
my $state = undef;
@@ -41,6 +42,10 @@ sub compute_hunk_header {
sub finish_hunk {
return unless defined $hunk_header;
if ($hunk_wheat =~ m{^[-+]}m) {
+ if ($diff_header) {
+ $wheat .= $diff_header;
+ $diff_header = "";
+ }
$wheat .= (compute_hunk_header $hunk_header, $hunk_wheat). $hunk_wheat;
}
$chaff .= (compute_hunk_header $hunk_header, $hunk_chaff) . $hunk_chaff;
@@ -53,6 +58,7 @@ while (<STDIN>) {
if (m{^diff}) {
finish_hunk();
$state = "diff header";
+ $diff_header = "";
}
if (m{^@@}) {
finish_hunk();
@@ -63,7 +69,7 @@ while (<STDIN>) {
next;
}
if ($state eq "diff header") {
- $wheat .= $_;
+ $diff_header .= $_;
$chaff .= $_;
next;
}