From: Michael Forney <mforney@mforney.org>
To: 9front@9front.org
Subject: [9front] git lca bug
Date: Sat, 05 Mar 2022 11:32:05 -0800 [thread overview]
Message-ID: <6223bab7.1c69fb81.6fc89.a14b@mx.google.com> (raw)
I recently encountered a bug where git/query returns the wrong
result when calculating LCA(A, B) in the following graph:
A
| B
| |
| C
| |
| D
| |
| E
| |
| F
| |
| G
| |
| H
| /
|/
I
|
J
|
K
|
L
|\
| \
M N
| /
|/
O
|
P
|
...
It returns M rather than I.
The LCA algorithm was rewritten not too long ago in
http://git.9front.org/plan9front/plan9front/c7dcc82b0be805717efbe77c98eaadf3ee1e31af/commit.html
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
<--a--b--c--d--e--f--g
\ /
+-----h-------
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
M
term%
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
M
term%
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?
next reply other threads:[~2022-03-05 19:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-05 19:32 Michael Forney [this message]
2022-03-06 3:44 ` ori
2022-03-06 5:21 ` Michael Forney
2022-03-06 18:33 ` ori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6223bab7.1c69fb81.6fc89.a14b@mx.google.com \
--to=mforney@mforney.org \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).