shithub: fork

Download patch

ref: 2b1975d6a669372c7d734213996d5123ee1c378f
parent: e4c57f3ea9cb88c50b47ca3c99b2adf85ab1a984
author: qwx <qwx@sciops.net>
date: Tue Aug 5 06:02:27 EDT 2025

git: pull from upstream

--- a/sys/src/cmd/git/get.c
+++ b/sys/src/cmd/git/get.c
@@ -9,6 +9,8 @@
 
 char *fetchbranch;
 char *upstream = "origin";
+Hash heads[64];
+int nheads;
 int listonly;
 
 /*
@@ -139,13 +141,19 @@
 }
 
 int
+prefixed(char *s, char *pfx)
+{
+	return strncmp(s, pfx, strlen(pfx)) == 0;
+}
+
+int
 branchmatch(char *br, char *pat)
 {
 	char name[128];
 
-	if(strstr(pat, "refs/heads") == pat)
+	if(prefixed(pat, "refs/heads"))
 		snprint(name, sizeof(name), "%s", pat);
-	else if(strstr(pat, "heads"))
+	else if(prefixed(pat, "heads/"))
 		snprint(name, sizeof(name), "refs/%s", pat);
 	else
 		snprint(name, sizeof(name), "refs/heads/%s", pat);
@@ -269,6 +277,10 @@
 			sysfatal("remote side sent invalid ref: %s", sp[1]);
 		if(fetchbranch && !branchmatch(sp[1], fetchbranch))
 			continue;
+		else if(strcmp(sp[1], "HEAD") != 0
+		&& !prefixed(sp[1], "refs/heads/")
+		&& !prefixed(sp[1], "refs/tags/"))
+			continue;
 		if(refsz == nref + 1){
 			refsz *= 2;
 			have = earealloc(have, refsz, sizeof(have[0]));
@@ -296,7 +308,7 @@
 			continue;
 		for(j = 0; j < i; j++)
 			if(hasheq(&want[i], &want[j]))
-				goto Next;
+				continue;
 		if((o = readobject(want[i])) != nil){
 			unref(o);
 			continue;
@@ -305,7 +317,6 @@
 			sysfatal("could not send want for %H", want[i]);
 		caps[0] = 0;
 		req = 1;
-Next:		continue;
 	}
 	flushpkt(c);
 
@@ -331,6 +342,22 @@
 		nsent++;
 	}
 	/*
+	 * The other branches we have probably make sense to send,
+	 * since often we'll be pulling a new branch with objects
+	 * that we already have; it's not entirely clear what we
+	 * want to do here.
+	 */
+	for(i = 0; i < nheads; i++){
+		if((o = readobject(heads[i])) == nil)
+			sysfatal("missing exected object: %H", have[i]);
+		if(fmtpkt(c, "have %H", o->hash) == -1)
+			sysfatal("write: %r");
+		enqueueparent(&haveq, o);
+		osadd(&hadobj, o);
+		unref(o);
+		nsent++;
+	}
+	/*
 	 * While we could short circuit this and check if upstream has
 	 * acked our objects, for the first 256 haves, this is simple
 	 * enough.
@@ -466,7 +493,14 @@
 	case 'u':	upstream=EARGF(usage());	break;
 	case 'd':	chattygit++;			break;
 	case 'l':	listonly++;			break;
-	default:	usage();			break;
+	case 'h':
+		if(nheads < nelem(heads))
+			if(hparse(&heads[nheads], EARGF(usage())) == 0)
+				nheads++;
+		break;
+	default:
+		usage();
+		break;
 	}ARGEND;
 
 	gitinit();
--