shithub: riscv

Download patch

ref: ace4e4defa70671fc0747c9899cfa80036efbb3d
parent: 79a7b4ae59c2e0352b354cf719bc7ef4055f83ae
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Feb 18 00:06:49 EST 2024

git/get: move ERR handling into protocol code

clean up error handling code, and make the error string
from server errors match what we exect.

--- a/sys/src/cmd/git/get.c
+++ b/sys/src/cmd/git/get.c
@@ -219,8 +219,6 @@
 			return -1;
 		if(n == 0)
 			break;
-		if(strncmp(buf, "ERR ", 4) == 0)
-			sysfatal("%s", buf + 4);
 
 		if(first && n > strlen(buf))
 			handlecaps(buf + strlen(buf) + 1);
--- a/sys/src/cmd/git/proto.c
+++ b/sys/src/cmd/git/proto.c
@@ -75,6 +75,12 @@
 		sysfatal("pktline: undersize buffer");
 	if(readn(c->rfd, buf, n) != n)
 		return -1;
+	if(n > 4 && strncmp(buf, "ERR ", 4) == 0){
+		if((e = strrchr(buf, '\n')) != nil)
+			*e = '\0';
+		werrstr("%s", buf + 4);
+		return -1;
+	}
 	buf[n] = 0;
 	tracepkt(1, "=r=>", buf, n);
 	return n;
--- a/sys/src/cmd/git/send.c
+++ b/sys/src/cmd/git/send.c
@@ -149,8 +149,6 @@
 		if(first && n > strlen(buf))
 			parsecaps(buf + strlen(buf) + 1, &cs);
 		first = 0;
-		if(strncmp(buf, "ERR ", 4) == 0)
-			sysfatal("%s", buf + 4);
 
 		if(getfields(buf, sp, nelem(sp), 1, " \t\r\n") != 2)
 			sysfatal("invalid ref line %.*s", utfnlen(buf, n), buf);