9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] git: please test
@ 2024-12-01  4:27 ori
  0 siblings, 0 replies; only message in thread
From: ori @ 2024-12-01  4:27 UTC (permalink / raw)
  To: 9front

this code should be a no-op, just refactors the capability
handling so that we can use it in the server side of git
cleanly too.

diff afe12c32f3368c088e82fdd4274408eaf68d14e2 uncommitted
--- a/sys/src/cmd/git/get.c
+++ b/sys/src/cmd/git/get.c
@@ -134,34 +134,7 @@
 	return strcmp(br, name) == 0;
 }
 
-char *
-matchcap(char *s, char *cap, int full)
-{
-	if(strncmp(s, cap, strlen(cap)) == 0)
-		if(!full || strlen(s) == strlen(cap))
-			return s + strlen(cap);
-	return nil;
-}
-
 void
-handlecaps(char *caps)
-{
-	char *p, *n, *c, *r;
-
-	for(p = caps; p != nil; p = n){
-		n = strchr(p, ' ');
-		if(n != nil)
-			*n++ = 0;
-		if((c = matchcap(p, "symref=", 0)) != nil){
-			if((r = strchr(c, ':')) != nil){
-				*r++ = '\0';
-				print("symref %s %s\n", c, r);
-			}
-		}
-	}
-}
-
-void
 fail(char *pack, char *idx, char *msg, ...)
 {
 	char buf[ERRMAX];
@@ -202,6 +175,7 @@
 	int nref, refsz, first, nsent;
 	int i, l, n, req, pfd;
 	vlong packsz;
+	Capset cs;
 	Objset hadobj;
 	Object *o;
 	Objq haveq;
@@ -220,8 +194,11 @@
 		if(n == 0)
 			break;
 
-		if(first && n > strlen(buf))
-			handlecaps(buf + strlen(buf) + 1);
+		if(first && n > strlen(buf)){
+			parsecaps(buf + strlen(buf) + 1, &cs);
+			if(cs.symfrom[0] != 0)
+				print("symref %s %s\n", cs.symfrom, cs.symto);
+		}
 		first = 0;
 
 		getfields(buf, sp, nelem(sp), 1, " \t\n\r");
--- a/sys/src/cmd/git/git.h
+++ b/sys/src/cmd/git/git.h
@@ -82,6 +82,14 @@
 	uchar h[20];
 };
 
+struct Capset {
+	char	symfrom[256];
+	char	symto[256];
+	int	sideband;
+	int	sideband64k;
+	int	report;
+};
+
 struct Conn {
 	int type;
 	int rfd;
@@ -330,6 +338,7 @@
 int	readphase(Conn *);
 int	writephase(Conn *);
 void	closeconn(Conn *);
+void	parsecaps(char *, Capset *);
 
 /* queues */
 void	qinit(Objq*);
--- a/sys/src/cmd/git/proto.c
+++ b/sys/src/cmd/git/proto.c
@@ -17,7 +17,43 @@
 	Nbranch	= 32,
 };
 
+char *
+matchcap(char *s, char *cap, int full)
+{
+	if(strncmp(s, cap, strlen(cap)) == 0)
+		if(!full || strlen(s) == strlen(cap))
+			return s + strlen(cap);
+	return nil;
+}
+
 void
+parsecaps(char *caps, Capset *cs)
+{
+	char *p, *n, *c, *t;
+
+	memset(cs, 0, sizeof(*cs));
+	for(p = caps; p != nil; p = n){
+		n = strchr(p, ' ');
+		if(n != nil)
+			*n++ = 0;
+		if(matchcap(p, "report-status", 1) != nil)
+			cs->report = 1;
+		else if(matchcap(p, "side-band", 1) != nil)
+			cs->sideband = 1;
+		else if(matchcap(p, "side-band-64k", 1) != nil)
+			cs->sideband64k = 1;
+		else if((c = matchcap(p, "symref=", 0)) != nil){
+			if((t = strchr(c, ':')) == nil)
+				continue;
+			*t++ = '\0';
+			snprint(cs->symfrom, sizeof(cs->symfrom), c);
+			snprint(cs->symto, sizeof(cs->symto), t);
+		}
+	}
+}
+
+
+void
 tracepkt(int v, char *pfx, char *b, int n)
 {
 	char *f;
@@ -158,7 +194,7 @@
 		snprint(port, Nport, "80");
 	else if(strncmp(proto, "hjgit", 5) == 0)
 		snprint(port, Nport, "17021");
-	else if(strncmp(proto, "gits", 4) == 0)
+	else if(strncmp(proto, "gits", 5) == 0)
 		snprint(port, Nport, "9419");
 	else
 		hasport = 0;
--- a/sys/src/cmd/git/send.c
+++ b/sys/src/cmd/git/send.c
@@ -3,15 +3,8 @@
 
 #include "git.h"
 
-typedef struct Capset	Capset;
 typedef struct Map	Map;
 
-struct Capset {
-	int	sideband;
-	int	sideband64k;
-	int	report;
-};
-
 struct Map {
 	char	*ref;
 	Hash	ours;
@@ -87,33 +80,6 @@
 	*tailp = tail;
 	*refp = ref;
 	return nu;	
-}
-
-char *
-matchcap(char *s, char *cap, int full)
-{
-	if(strncmp(s, cap, strlen(cap)) == 0)
-		if(!full || strlen(s) == strlen(cap))
-			return s + strlen(cap);
-	return nil;
-}
-
-void
-parsecaps(char *caps, Capset *cs)
-{
-	char *p, *n;
-
-	for(p = caps; p != nil; p = n){
-		n = strchr(p, ' ');
-		if(n != nil)
-			*n++ = 0;
-		if(matchcap(p, "report-status", 1) != nil)
-			cs->report = 1;
-		if(matchcap(p, "side-band", 1) != nil)
-			cs->sideband = 1;
-		if(matchcap(p, "side-band-64k", 1) != nil)
-			cs->sideband64k = 1;
-	}
 }
 
 int


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-12-01  4:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-01  4:27 [9front] git: please test ori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).