shithub: git9

Download patch

ref: 423e875b89b475d2009e465dd061c8b2bc2302a0
parent: f8bf36dc99975ea582975096522f6acece3e4bf6
author: Ori Bernstein <[email protected]>
date: Sat Oct 12 02:12:22 EDT 2019

Git/query now merges args into one query.

--- a/fetch.c
+++ b/fetch.c
@@ -69,7 +69,7 @@
 {
 	DigestState *st;
 	Hash hexpect;
-	char buf[65536];
+	char buf[Pktmax];
 	vlong n, r;
 	int nr;
 	
@@ -138,7 +138,7 @@
 int
 fetchpack(int fd, int pfd, char *packtmp)
 {
-	char buf[65536], idxtmp[256], *sp[3];
+	char buf[Pktmax], idxtmp[256], *sp[3];
 	Hash h, *have, *want;
 	int nref, refsz;
 	int i, n, req;
--- a/git.1
+++ b/git.1
@@ -117,7 +117,7 @@
 [
 .B -pc
 ]
-.I query...
+.I query
 .PP
 .B git/walk
 [
--- a/git.h
+++ b/git.h
@@ -17,9 +17,10 @@
 
 enum {
 	/* 5k objects should be enough */
-	Cachemax=5*1024,
-	Pathmax=512,
-	Hashsz=20,
+	Cachemax	= 5*1024,
+	Pathmax		= 512,
+	Hashsz		= 20,
+	Pktmax		= 65536,
 
 	Nproto	= 16,
 	Nport	= 16,
--- a/query.c
+++ b/query.c
@@ -75,7 +75,7 @@
 void
 usage(void)
 {
-	fprint(2, "usage: %s [-pc] query...\n", argv0);
+	fprint(2, "usage: %s [-pc] query\n", argv0);
 	exits("usage");
 }
 
@@ -84,7 +84,8 @@
 {
 	int i, j, n;
 	Hash *h;
-	char *p;
+	char *p, *e;
+	char query[2048];
 
 	ARGBEGIN{
 	case 'p':	fullpath++;	break;
@@ -94,18 +95,20 @@
 
 	gitinit();
 	fmtinstall('P', Pfmt);
-	for(i = 0; i < argc; i++){
-		if((n = resolverefs(&h, argv[i])) == -1)
-			sysfatal("resolve %s: %r", argv[i]);
-		if(changes){
-			if(n != 2)
-				sysfatal("diff: need 2 commits, got %d", n);
-			difftrees(h[0], h[1]);
-		}else{
-			p = (fullpath ? "/mnt/git/object/" : "");
-			for(j = 0; j < n; j++)
-				print("%s%H\n", p, h[j]);
-		}
+	p = query;
+	e = query + nelem(query);
+	for(i = 0; i < argc; i++)
+		p = seprint(p, e, "%s ", argv[i]);
+	if((n = resolverefs(&h, query)) == -1)
+		sysfatal("resolve %s: %r", argv[i]);
+	if(changes){
+		if(n != 2)
+			sysfatal("diff: need 2 commits, got %d", n);
+		difftrees(h[0], h[1]);
+	}else{
+		p = (fullpath ? "/mnt/git/object/" : "");
+		for(j = 0; j < n; j++)
+			print("%s%H\n", p, h[j]);
 	}
 	exits(nil);
 }
--- a/send.c
+++ b/send.c
@@ -288,7 +288,7 @@
 sendpack(int fd)
 {
 	int i, n, r, nupd, nsp, updating;
-	char buf[65536], *sp[3];
+	char buf[Pktmax], *sp[3];
 	Update *upd, *u;
 	Object *a, *b;