git/query: leave range commits in topological order

This prevents commits from getting reordered incorrectly during rebase
or export.
This commit is contained in:
Michael Forney 2022-01-23 00:39:21 +00:00 committed by Ori Bernstein
parent b9adc507d2
commit a5a8a92adf

View file

@ -51,26 +51,6 @@ eatspace(Eval *ev)
ev->p++; ev->p++;
} }
int
objdatecmp(void *pa, void *pb)
{
Object *a, *b;
int r;
a = readobject((*(Object**)pa)->hash);
b = readobject((*(Object**)pb)->hash);
assert(a->type == GCommit && b->type == GCommit);
if(a->commit->mtime == b->commit->mtime)
r = 0;
else if(a->commit->mtime < b->commit->mtime)
r = -1;
else
r = 1;
unref(a);
unref(b);
return r;
}
void void
push(Eval *ev, Object *o) push(Eval *ev, Object *o)
{ {
@ -406,7 +386,7 @@ static int
range(Eval *ev) range(Eval *ev)
{ {
Object *a, *b, *p, *q, **all; Object *a, *b, *p, *q, **all;
int nall, *idx, mark; int nall, *idx;
Objset keep, skip; Objset keep, skip;
b = pop(ev); b = pop(ev);
@ -424,7 +404,6 @@ range(Eval *ev)
all = nil; all = nil;
idx = nil; idx = nil;
nall = 0; nall = 0;
mark = ev->nstk;
osinit(&keep); osinit(&keep);
osinit(&skip); osinit(&skip);
osadd(&keep, a); osadd(&keep, a);
@ -459,7 +438,6 @@ range(Eval *ev)
nall++; nall++;
} }
free(all); free(all);
qsort(ev->stk + mark, ev->nstk - mark, sizeof(Object*), objdatecmp);
return 0; return 0;
error: error:
free(all); free(all);