mirror of
https://github.com/mawww/kakoune.git
synced 2024-08-17 00:30:26 +03:00
rc tools patch: skip patch message signature, fixing diff application
Patches as produced by "git format-patch" have a trailing signature that is separated from the body by a line with "-- " on it. By default it contains the Git version. We erroneously include this signature in the diff we pipe to patch, which fails to apply as a result. Add a targeted fix to suppress these signatures.
This commit is contained in:
parent
c7eeb0ead5
commit
11e7e2964c
@ -25,6 +25,8 @@ my $state = undef;
|
||||
my $hunk_wheat = undef;
|
||||
my $hunk_chaff = undef;
|
||||
my $hunk_header = undef;
|
||||
my $hunk_remaining_lines = undef;
|
||||
my $signature = "";
|
||||
|
||||
sub compute_hunk_header {
|
||||
my $original_header = shift;
|
||||
@ -48,7 +50,7 @@ sub finish_hunk {
|
||||
}
|
||||
$wheat .= (compute_hunk_header $hunk_header, $hunk_wheat). $hunk_wheat;
|
||||
}
|
||||
$chaff .= (compute_hunk_header $hunk_header, $hunk_chaff) . $hunk_chaff;
|
||||
$chaff .= (compute_hunk_header $hunk_header, $hunk_chaff) . $hunk_chaff . $signature;
|
||||
$hunk_header = undef;
|
||||
}
|
||||
|
||||
@ -60,12 +62,18 @@ while (<STDIN>) {
|
||||
$state = "diff header";
|
||||
$diff_header = "";
|
||||
}
|
||||
if (m{^@@}) {
|
||||
if ($state eq "signature") {
|
||||
$signature .= $_;
|
||||
next;
|
||||
}
|
||||
if (m{^@@ -\d+(?:,(\d)+)? \+\d+(?:,\d+)? @@}) {
|
||||
$hunk_remaining_lines = $1 or 1;
|
||||
finish_hunk();
|
||||
$state = "diff hunk";
|
||||
$hunk_header = $_;
|
||||
$hunk_wheat = "";
|
||||
$hunk_chaff = "";
|
||||
$signature = "";
|
||||
next;
|
||||
}
|
||||
if ($state eq "diff header") {
|
||||
@ -73,6 +81,12 @@ while (<STDIN>) {
|
||||
$chaff .= $_;
|
||||
next;
|
||||
}
|
||||
if ($hunk_remaining_lines == 0 and m{^-- $}) {
|
||||
$state = "signature";
|
||||
$signature .= $_;
|
||||
next;
|
||||
}
|
||||
--$hunk_remaining_lines if m{^[ -]};
|
||||
my $include = m{^ } || ($lineno >= $min_line && $lineno <= $max_line);
|
||||
if ($include) {
|
||||
$hunk_wheat .= $_;
|
||||
|
1
test/tools/patch/signature/cmd
Normal file
1
test/tools/patch/signature/cmd
Normal file
@ -0,0 +1 @@
|
||||
%:patch tee applied.diff<ret><ret>!echo Applied:; cat applied.diff; echo; echo Updated buffer:<ret>
|
10
test/tools/patch/signature/in
Normal file
10
test/tools/patch/signature/in
Normal file
@ -0,0 +1,10 @@
|
||||
diff -ur a/file1 b/file1
|
||||
--- a/file1
|
||||
+++ b/file1
|
||||
@@ -1,3 +1,3 @@
|
||||
context
|
||||
-file1 here
|
||||
+modified file1 here
|
||||
context
|
||||
--
|
||||
2.43.0
|
20
test/tools/patch/signature/out
Normal file
20
test/tools/patch/signature/out
Normal file
@ -0,0 +1,20 @@
|
||||
Applied:
|
||||
diff -ur a/file1 b/file1
|
||||
--- a/file1
|
||||
+++ b/file1
|
||||
@@ -1,3 +1,3 @@
|
||||
context
|
||||
-file1 here
|
||||
+modified file1 here
|
||||
context
|
||||
|
||||
Updated buffer:
|
||||
diff -ur a/file1 b/file1
|
||||
--- a/file1
|
||||
+++ b/file1
|
||||
@@ -1,3 +1,3 @@
|
||||
context
|
||||
modified file1 here
|
||||
context
|
||||
--
|
||||
2.43.0
|
1
test/tools/patch/signature/rc
Normal file
1
test/tools/patch/signature/rc
Normal file
@ -0,0 +1 @@
|
||||
source "%val{runtime}/rc/tools/patch.kak"
|
Loading…
Reference in New Issue
Block a user