aboutsummaryrefslogtreecommitdiff
path: root/vipatch
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-25 14:28:09 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-25 14:28:09 +0200
commitc7cc59d242bf0e09a03e4bba111f987474d6b25f (patch)
tree5440622f6e5c7f03d26d89d08efd3dcbe56a3cbb /vipatch
parentd825a4995fa8e663688fb106d02d14759cf58906 (diff)
downloadpatches-c7cc59d242bf0e09a03e4bba111f987474d6b25f.tar.gz
vipatch: Support multiple diff headers for the same file
Diffstat (limited to 'vipatch')
-rwxr-xr-xvipatch30
1 files changed, 16 insertions, 14 deletions
diff --git a/vipatch b/vipatch
index 4711388..d860f93 100755
--- a/vipatch
+++ b/vipatch
@@ -7,16 +7,23 @@
# number of added/removed lines.
ep | awk -vname=${0##*/} '
-/^@@ / { head = $0 "\n"; next }
-head && /^---/ { printpatch(); print; next }
-head && /^\+/ { plus++ }
-head && /^-/ { minus++ }
-head && /^ / { same++ }
-head { body = body $0 "\n"; next }
- { print }
-END { if (head) printpatch() }
+/^@@ / { if (head) printpatch(); head = $0 "\n"; next }
+head && /^---/ { print; next }
+head && /^\+\+\+/ { print; next }
+head && /^\+/ { plus++ }
+head && /^-/ { minus++ }
+head && /^ / { same++ }
+head { body = body $0 "\n"; next }
+ { print }
+END { if (head) printpatch() }
function printpatch() {
+ match(head, /^@@ -[0-9]+,[0-9]+ \+[0-9]+,/)
+ prefix = substr(head, RSTART, RLENGTH)
+
+ match(head, / @@.*/)
+ suffix = substr(head, RSTART, RLENGTH)
+
match(head, /,[0-9]+/)
old = substr(head, RSTART+1, RLENGTH-1)
new = old + plus - minus
@@ -26,16 +33,11 @@ function printpatch() {
printf "%s: %d %s incorrectly %s\n", name, abs(diff),
(abs(diff) > 1) ? "lines" : "line",
(diff > 0) ? "removed" : "added" > "/dev/stderr"
+ printf "under header%s\n", substr(suffix, 4) > "/dev/stderr"
head = ""
exit 1
}
- match(head, /^@@ -[0-9]+,[0-9]+ \+[0-9]+,/)
- prefix = substr(head, RSTART, RLENGTH)
-
- match(head, / @@.*/)
- suffix = substr(head, RSTART, RLENGTH)
-
printf "%s%d%s", prefix, new, suffix
printf "%s", body