shithub: git9

Download patch

ref: 34814c675be8a8f324fbc7594ad862506db455d9
parent: 8d3a8f8fcbb24dc0de86a7702cb1a30492b450e1
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Nov 29 00:44:00 EST 2020

git/query: make it possible query all history

Git/query now accepts the zero hash, 000000....00000,
as a parameter for git/query, and treats it as the
commit before the first commit. This means that

	git/query 000000000000..HEAD

is an easy way of getting all commits in history.

--- a/ref.c
+++ b/ref.c
@@ -35,6 +35,10 @@
 	int	color;
 };
 
+static Object zcommit = {
+	.type=GCommit
+};
+
 void
 eatspace(Eval *ev)
 {
@@ -52,7 +56,7 @@
 	assert(a->type == GCommit && b->type == GCommit);
 	if(a->commit->mtime == b->commit->mtime)
 		return 0;
-	else if(a->commit->mtime < b->commit->mtime)
+	else if(a->commit->mtime > b->commit->mtime)
 		return -1;
 	else
 		return 1;
@@ -415,7 +419,7 @@
 		idx = erealloc(idx, (nall + 1)*sizeof(int));
 		all[nall] = p;
 		idx[nall] = 0;
-		if(p == a)
+		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)
@@ -431,6 +435,8 @@
 			break;
 		if((p = readobject(p->commit->parent[idx[nall]])) == nil)
 			sysfatal("bad commit %H", p->commit->parent[idx[nall]]);
+		if(p->type != GCommit)
+			sysfatal("not commit: %H", p->hash);
 		nall++;
 	}
 	free(all);
@@ -494,7 +500,10 @@
 	if(readref(&h, name) == -1){
 		werrstr("invalid ref %s", name);
 		return -1;
-	}else if((o = readobject(h)) == nil){
+	}
+	if(hasheq(&h, &Zhash))
+		o = &zcommit;
+	else if((o = readobject(h)) == nil){
 		werrstr("invalid ref %s (hash %H)", name, h);
 		return -1;
 	}