9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] git lca bug
@ 2022-03-05 19:32 Michael Forney
  2022-03-06  3:44 ` ori
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Forney @ 2022-03-05 19:32 UTC (permalink / raw)
  To: 9front

I recently encountered a bug where git/query returns the wrong
result when calculating LCA(A, B) in the following graph:

|  B
|  |
|  C
|  |
|  D
|  |
|  E
|  |
|  F
|  |
|  G
|  |
|  H
| /
| \
M  N
| / 

It returns M rather than I.

The LCA algorithm was rewritten not too long ago in

However, I don't understand that commit message. The definition of
LCA(b, g) that I've read is "the lowest node that has both b and g
as descendents". In the graph

        \               /

the lowest node that fits this definition is b. a is not the LCA,
since b is a descendent of a, and therefore lower.

I'm not sure what is meant by strict LCA, but maybe there is some
other definition of LCA that finds the ancestor whose distances
between the two nodes is minimized in some way? What metric was
used here? Perhaps sum of distances?

It seems to me that what we actually want to find is a common
ancestor such that there is no other common ancestor that descends
from it. I don't think the distances between the LCA arguments and
the ancestor are relevant here, except maybe to break ties when
there are multiple LCAs.

Here's a debug log with commit hashes replaced with the letter in
the problematic graph:

term% git/query -dd A B
init: keep A
init: drop B
finding twixt commits
found best (dist 7 < 1073741824): I
found best (dist 5 < 7): M
found ancestor

term% git/query -dd A B
init: keep A
init: drop B
finding twixt commits
	enqueue: keep I
	enqueue: drop C
	enqueue: keep J
	enqueue: keep K
	enqueue: keep L
	enqueue: keep M
	enqueue: keep N
	enqueue: keep O
	enqueue: keep P
	enqueue: keep Q
	enqueue: keep R
	enqueue: keep S
	enqueue: keep T
	enqueue: keep U
	enqueue: keep V
	enqueue: keep W
	enqueue: keep X
	enqueue: keep Y
	enqueue: keep Z
	enqueue: keep AA
	enqueue: keep AB
	enqueue: keep AC
	enqueue: keep AD
	enqueue: drop D
	enqueue: drop E
	enqueue: drop F
	enqueue: drop G
	enqueue: drop H
	enqueue: drop I
found best (dist 7 < 1073741824): I
repaint: blank => drop AD
repaint: blank => drop M
found best (dist 5 < 7): M
found ancestor

Here's what I think is going wrong:
- We paint commits reachable from A as Keep, and eventually we get
  to a commit with timestamp earlier than B. The remaining ancestors
  (M and AD) are left on the queue.
- We start painting commits reachable from B as Drop and eventually
  find I, marking that as the current best with distance 7 (from B).
- We repaint the commits reachable from I as Drop, until we get to
  the ancestors not yet marked (M and AD).
- We continue with what was left on the queue, M and AD. M is painted
  Drop, and was queued as Keep, so this is a new common ancestor.
- M's distance (from A) is 5, which is lower than 7, so we use that
  in preference to I (even though I only had distance 1 from A).

Any idea on how best to fix this?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-06 18:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-05 19:32 [9front] git lca bug Michael Forney
2022-03-06  3:44 ` ori
2022-03-06  5:21   ` Michael Forney
2022-03-06 18:33     ` ori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).