shithub: git9

Download patch

ref: 7ea214c75673ba79e91196c8f472ba2e25038c2f
parent: 3f64088be2100710c039baa8ace39baf692c5d30
author: Ori Bernstein <[email protected]>
date: Tue Dec 15 10:22:02 EST 2020

git/query: revert invalid change to range computation

The old git/query was shitty, but it didn't loop forever.
TODO: replace it with something better.

--- a/query.c
+++ b/query.c
@@ -7,7 +7,6 @@
 
 int fullpath;
 int changes;
-int reverse;
 char *path[128];
 int npath;
 
@@ -128,7 +127,7 @@
 void
 main(int argc, char **argv)
 {
-	int i, j, n, idx;
+	int i, j, n;
 	Hash *h;
 	char *p, *e, *s;
 	char query[2048], repo[512];
@@ -136,7 +135,6 @@
 	ARGBEGIN{
 	case 'p':	fullpath++;	break;
 	case 'c':	changes++;	break;
-	case 'r':	reverse++;	break;
 	default:	usage();	break;
 	}ARGEND;
 
@@ -164,10 +162,8 @@
 		difftrees(h[0], h[1]);
 	}else{
 		p = (fullpath ? "/mnt/git/object/" : "");
-		for(j = 0; j < n; j++){
-			idx = reverse ? j : n - j - 1;
-			print("%s%H\n", p, h[idx]);
-		}
+		for(j = 0; j < n; j++)
+			print("%s%H\n", p, h[j]);
 	}
 	exits(nil);
 }
--- a/ref.c
+++ b/ref.c
@@ -415,11 +415,14 @@
 	osinit(&keep);
 	osinit(&skip);
 	while(1){
-		all = erealloc(all, (nall + 1)*sizeof(Object*));
-		idx = erealloc(idx, (nall + 1)*sizeof(int));
+		all = earealloc(all, (nall + 1), sizeof(Object*));
+		idx = earealloc(idx, (nall + 1), sizeof(int));
 		all[nall] = p;
 		idx[nall] = 0;
-		if(p->commit->nparent == 0)
+		if(p == a || p->commit->nparent == 0 && a == &zcommit)
+			if((nall = unwind(ev, all, idx, nall, &p, &keep, 1)) == -1)
+				break;
+		else if(p->commit->nparent == 0)
 			if((nall = unwind(ev, all, idx, nall, &p, &skip, 0)) == -1)
 				break;
 		else if(oshas(&keep, p->hash))
@@ -428,7 +431,6 @@
 		else if(oshas(&skip, p->hash))
 			if((nall = unwind(ev, all, idx, nall, &p, &skip, 0)) == -1)
 				break;
-
 		if(p->commit->nparent == 0)
 			break;
 		if((p = readobject(p->commit->parent[idx[nall]])) == nil)
@@ -435,10 +437,7 @@
 			sysfatal("bad commit %H", p->commit->parent[idx[nall]]);
 		if(p->type != GCommit)
 			sysfatal("not commit: %H", p->hash);
-		if(p == a || p->commit->nparent == 0 && a == &zcommit)
-			if((nall = unwind(ev, all, idx, nall, &p, &keep, 1)) == -1)
-				break;
- 		nall++;
+		nall++;
 	}
 	free(all);
 	qsort(ev->stk + mark, ev->nstk - mark, sizeof(Object*), objdatecmp);