ref: eccbd1ecccca36d7c624ded19e78fa3254cf5600
parent: 1748296ca86784fb84c9070ad6d2bb7bc9406173
author: Ori Bernstein <ori@eigenstate.org>
date: Sat May 24 20:07:36 EDT 2025
patch: add '-d' flag to make applying patches less clunky
--- a/sys/man/1/patch
+++ b/sys/man/1/patch
@@ -28,6 +28,10 @@
.PP
The following options are supported:
.TP
+.BI -d \ dir
+Interpret paths in the patch file relative to
+.IR dir .
+.TP
.B -R
Reverse direction of the patch. Additions become removals,
and the new and old file names are swapped.
--- a/sys/src/cmd/patch.c
+++ b/sys/src/cmd/patch.c
@@ -50,6 +50,7 @@
int strip;
int reverse;
+char *workdir;
Fchg *changed;
int nchanged;
int dryrun;
@@ -699,6 +700,9 @@
int i, ok;
ARGBEGIN{
+ case 'd':
+ workdir = EARGF(usage());
+ break;
case 'p':
strip = atoi(EARGF(usage()));
break;
@@ -732,6 +736,8 @@
sysfatal("open %s: %r", argv[i]);
if((p = parse(f, argv[i])) == nil)
sysfatal("parse patch: %r");
+ if(workdir != nil && chdir(workdir) == -1)
+ sysfatal("chdir %s: %r", workdir);
if(apply(p, argv[i]) == -1){
fprint(2, "apply %s: %r\n", argv[i]);
ok = 0;
--
⑨