diff options
author | Omar Polo <op@cvs.openbsd.org> | 2022-08-03 07:25:45 +0000 |
---|---|---|
committer | Omar Polo <op@cvs.openbsd.org> | 2022-08-03 07:25:45 +0000 |
commit | 247b3301659b6ab6a3562d7bded858f486557fe9 (patch) | |
tree | b70be6e0e30606156c23dfc615f292c301024aed /usr.bin | |
parent | 79eef10a8400b726a22c3a3b515388a19e2c980c (diff) |
fix dwim for reversed patches
patch(1) fails to recognize the reversal application of a patch that
cerates a file. since an empty context always matches, the idea is to
run the dwim ("do what I mean") code also when locate_hunk succeeds but
the patch would create a file and the match is on the first line.
fixes the (disabled) test t3.
ok stsp@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/patch/patch.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c index 1d9070b0184..00f9e3f2a59 100644 --- a/usr.bin/patch/patch.c +++ b/usr.bin/patch/patch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: patch.c,v 1.69 2019/12/02 22:17:32 jca Exp $ */ +/* $OpenBSD: patch.c,v 1.70 2022/08/03 07:25:44 op Exp $ */ /* * patch - a program to apply diffs to original files @@ -260,7 +260,8 @@ main(int argc, char *argv[]) if (!skip_rest_of_patch) { do { where = locate_hunk(fuzz); - if (hunk == 1 && where == 0 && !force) { + if ((hunk == 1 && where == 0 && !force) || + (where == 1 && pch_ptrn_lines() == 0 && !force)) { /* dwim for reversed patch? */ if (!pch_swap()) { if (fuzz == 0) @@ -276,6 +277,10 @@ main(int argc, char *argv[]) /* put it back to normal */ fatal("lost hunk on alloc error!\n"); reverse = !reverse; + + /* restore position if this patch creates a file */ + if (pch_ptrn_lines() == 0) + where = 1; } else if (noreverse) { if (!pch_swap()) /* put it back to normal */ |