ref: 215c3439912b03036266910eacd74e2f46f99bd8
parent: 12407c20b7b6788307cbbea0251e4f2f338d629b
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Dec 2 23:03:50 EST 2020
git/query: don't include start of range in .. operator Match behavior of git, act more usefully in git/log and scripting.
--- a/query.c
+++ b/query.c
@@ -7,6 +7,7 @@
int fullpath;
int changes;
+int reverse;
char *path[128];
int npath;
@@ -127,7 +128,7 @@
void
main(int argc, char **argv)
{
- int i, j, n;
+ int i, j, n, idx;
Hash *h;
char *p, *e, *s;
char query[2048], repo[512];
@@ -135,6 +136,7 @@
ARGBEGIN{
case 'p': fullpath++; break;
case 'c': changes++; break;
+ case 'r': reverse++; break;
default: usage(); break;
}ARGEND;
@@ -162,8 +164,10 @@
difftrees(h[0], h[1]);
}else{
p = (fullpath ? "/mnt/git/object/" : "");
- for(j = 0; j < n; j++)
- print("%s%H\n", p, h[j]);
+ for(j = 0; j < n; j++){
+ idx = reverse ? j : n - j - 1;
+ print("%s%H\n", p, h[idx]);
+ }
}
exits(nil);
}
--- a/ref.c
+++ b/ref.c
@@ -419,10 +419,7 @@
idx = erealloc(idx, (nall + 1)*sizeof(int));
all[nall] = p;
idx[nall] = 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(p->commit->nparent == 0)
if((nall = unwind(ev, all, idx, nall, &p, &skip, 0)) == -1)
break;
else if(oshas(&keep, p->hash))
@@ -431,6 +428,7 @@
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)
@@ -437,7 +435,10 @@
sysfatal("bad commit %H", p->commit->parent[idx[nall]]);
if(p->type != GCommit)
sysfatal("not commit: %H", p->hash);
- nall++;
+ if(p == a || p->commit->nparent == 0 && a == &zcommit)
+ if((nall = unwind(ev, all, idx, nall, &p, &keep, 1)) == -1)
+ break;
+ nall++;
}
free(all);
qsort(ev->stk + mark, ev->nstk - mark, sizeof(Object*), objdatecmp);