diff options
author | Ori Bernstein <ori@eigenstate.org> | 2021-09-11 17:46:26 +0000 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2021-09-11 17:46:26 +0000 |
commit | c7dcc82b0be805717efbe77c98eaadf3ee1e31af (patch) | |
tree | 939430f07438b7f88749cb9680ba97df09ca6c14 /sys/src/cmd/git/util.c | |
parent | 546f8cfeca6fca0b6b246c8dbf035027e3f15f8c (diff) |
git/query: fix spurious merge requests
Due to the way LCA is defined, a using a strict LCA
on a graph like this:
<--a--b--c--d--e--f--g
\ /
+-----h-------
can lead to spurious requests to merge. This happens
because 'lca(b, g)' would return 'a', since it can be
reached in one step from 'b', and 2 steps from 'g', while
reaching 'b' from 'a' would be a longer path.
As a result, we need to implement an lca variant that
returns the starting node if one is reachable from the
other, even if it's already found the technically correct
least common ancestor.
This replaces our LCA algorithm with one based on the
painting we do while finding a twixt, making it give
the resutls we want.
git/query: fix spurious merge requests
Due to the way LCA is defined, a using a strict LCA
on a graph like this:
<--a--b--c--d--e--f--g
\ /
+-----h-------
can lead to spurious requests to merge. This happens
because 'lca(b, g)' would return 'a', since it can be
reached in one step from 'b', and 2 steps from 'g', while
reaching 'b' from 'a' would be a longer path.
As a result, we need to implement an lca variant that
returns the starting node if one is reachable from the
other, even if it's already found the technically correct
least common ancestor.
This replaces our LCA algorithm with one based on the
painting we do while finding a twixt.
Diffstat (limited to 'sys/src/cmd/git/util.c')
-rw-r--r-- | sys/src/cmd/git/util.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/sys/src/cmd/git/util.c b/sys/src/cmd/git/util.c index 5ae897d3a..7a3139f95 100644 --- a/sys/src/cmd/git/util.c +++ b/sys/src/cmd/git/util.c @@ -321,3 +321,74 @@ showprogress(int x, int pct) } return pct; } + +void +qinit(Objq *q) +{ + memset(q, 0, sizeof(Objq)); + q->nheap = 0; + q->heapsz = 8; + q->heap = eamalloc(q->heapsz, sizeof(Qelt)); +} + +void +qclear(Objq *q) +{ + free(q->heap); +} + +void +qput(Objq *q, Object *o, int color, int dist) +{ + Qelt t; + int i; + + if(q->nheap == q->heapsz){ + q->heapsz *= 2; + q->heap = earealloc(q->heap, q->heapsz, sizeof(Qelt)); + } + q->heap[q->nheap].o = o; + q->heap[q->nheap].color = color; + q->heap[q->nheap].dist = dist; + q->heap[q->nheap].mtime = o->commit->mtime; + for(i = q->nheap; i > 0; i = (i-1)/2){ + if(q->heap[i].mtime < q->heap[(i-1)/2].mtime) + break; + t = q->heap[i]; + q->heap[i] = q->heap[(i-1)/2]; + q->heap[(i-1)/2] = t; + } + q->nheap++; +} + +int +qpop(Objq *q, Qelt *e) +{ + int i, l, r, m; + Qelt t; + + if(q->nheap == 0) + return 0; + *e = q->heap[0]; + if(--q->nheap == 0) + return 1; + + i = 0; + q->heap[0] = q->heap[q->nheap]; + while(1){ + m = i; + l = 2*i+1; + r = 2*i+2; + if(l < q->nheap && q->heap[m].mtime < q->heap[l].mtime) + m = l; + if(r < q->nheap && q->heap[m].mtime < q->heap[r].mtime) + m = r; + if(m == i) + break; + t = q->heap[m]; + q->heap[m] = q->heap[i]; + q->heap[i] = t; + i = m; + } + return 1; +} |