summaryrefslogtreecommitdiff
path: root/sys/src/cmd/patch.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2022-07-02 20:13:31 +0000
committerOri Bernstein <ori@eigenstate.org>2022-07-02 20:13:31 +0000
commitd457233c70ef6aa28861dd2978e92968ffba0920 (patch)
tree05e5d581c566b6f58f629bba81d9b45467d8915a /sys/src/cmd/patch.c
parent6dbfe8c3562b8ccf630ed0e3099b47c8d2730d14 (diff)
patch: handle stripped/empty lines mid-hunk
Some programs will strip trailing spaces from hunks; in this case we want to treat the line as though it came with a leading space. This fixes applying some patches, such as [PATCH] Permissions for child boards in /srv
Diffstat (limited to 'sys/src/cmd/patch.c')
-rw-r--r--sys/src/cmd/patch.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/sys/src/cmd/patch.c b/sys/src/cmd/patch.c
index 3da0674ff..d1b9db5fe 100644
--- a/sys/src/cmd/patch.c
+++ b/sys/src/cmd/patch.c
@@ -287,13 +287,13 @@ hunk:
while(1){
if((ln = readline(f, &lnum)) == nil){
if(oldcnt != h.oldcnt || newcnt != h.newcnt)
- sysfatal("%s:%d: malformed hunk", name, lnum);
+ sysfatal("%s:%d: malformed hunk: mismatched counts", name, lnum);
addhunk(p, &h);
break;
}
switch(ln[0]){
default:
- sysfatal("%s:%d: malformed hunk2", name, lnum);
+ sysfatal("%s:%d: malformed hunk: leading junk", name, lnum);
goto out;
case '-':
addold(&h, ln);
@@ -303,6 +303,12 @@ hunk:
addnew(&h, ln);
newcnt++;
break;
+ case '\n':
+ addold(&h, " \n");
+ addnew(&h, " \n");
+ oldcnt++;
+ newcnt++;
+ break;
case ' ':
addold(&h, ln);
addnew(&h, ln);
@@ -312,7 +318,7 @@ hunk:
}
free(ln);
if(oldcnt > h.oldcnt || newcnt > h.newcnt)
- sysfatal("%s:%d: malformed hunk", name, lnum);
+ sysfatal("%s:%d: malformed hunk: oversized hunk", name, lnum);
if(oldcnt < h.oldcnt || newcnt < h.newcnt)
continue;