shithub: riscv

Download patch

ref: 5e010fd8a82ec3b6552b4002bcd4be0586081e9a
parent: f79ba91129f15c3804a4e836cbfb822608a1059b
author: Ori Bernstein <[email protected]>
date: Tue Jan 30 17:58:19 EST 2024

vdiff: add support for stripping path elements when plumbing

Git generates patches with spurious leading path elements for
compatibility with Torvalds git; This means that we want to
strip them out when interacting with patches. The '-p'option
add support for this element stripping in git

--- a/sys/man/1/vdiff
+++ b/sys/man/1/vdiff
@@ -6,6 +6,10 @@
 [
 .B -b
 ]
+[
+.B -p
+.I strip
+]
 .SH DESCRIPTION
 .I vdiff
 reads unified diff output from standard input and displays a colored version. Right clicking on a line will send a 
@@ -22,6 +26,13 @@
 The
 .B \-b
 flag changes the color scheme to white text on a black background.
+.PP
+The
+.B \-p
+.I nstrip
+flag removes
+.I nstrip
+path elements from path before plumbing.
 .SH EXAMPLE
 % git/diff |vdiff
 .SH SOURCE
--- a/sys/src/cmd/vdiff.c
+++ b/sys/src/cmd/vdiff.c
@@ -61,17 +61,21 @@
 int lcount;
 int maxlength;
 int Δpan;
+int nstrip;
 const char ellipsis[] = "...";
 
 void
 plumb(char *f, int l)
 {
-	int fd;
-	char wd[256], addr[300]={0};
+	int fd, i;
+	char *p, wd[256], addr[300]={0};
 
 	fd = plumbopen("send", OWRITE);
 	if(fd<0)
 		return;
+	for(i = 0; i < nstrip; i++)
+		if((p = strchr(f, '/')) != nil)
+			f = p;
 	getwd(wd, sizeof wd);
 	snprint(addr, sizeof addr, "%s:%d", f, l);
 	plumbsendtext(fd, "vdiff", "edit", wd, addr);
@@ -415,7 +419,7 @@
 void
 usage(void)
 {
-	fprint(2, "%s [-b]\n", argv0);
+	fprint(2, "%s [-b] [-p n]\n", argv0);
 	exits("usage");
 }
 
@@ -439,6 +443,9 @@
 	ARGBEGIN{
 	case 'b':
 		b = 1;
+		break;
+	case 'p':
+		nstrip = atoi(EARGF(usage()));
 		break;
 	default:
 		usage();