Bug 5979 - revlog.ancestors emits nodes before their descendants, not strictly topological
Summary: revlog.ancestors emits nodes before their descendants, not strictly topological
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: 4.7.1
Hardware: All All
: wish bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-05 08:40 UTC by Axel Hecht
Modified: 2018-09-18 00:00 UTC (History)
2 users (show)

See Also:
Python Version: ---


Attachments
test case (683 bytes, text/plain)
2018-09-06 04:26 UTC, Axel Hecht
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Axel Hecht 2018-09-05 08:40 UTC
When looking at the ancestors of https://hg.mozilla.org/mozilla-central/graph/5f217a0d0473, I see a child parent emitted before it's child, which I don't expect. The comment says reversed topological order.


ancestors=repo.changelog.ancestors([494205], inclusive=True)
print('\n'.join('{} {} {}'.format(repo[r].hex()[:20], i, r) for r, i in zip(ancestors, range(21))))

ends in 

ca7b0659636ce6e6c836 18 494156
d14aaf65a80b3baddb19 19 494154
1c08b566a5c51e7c4f50 20 494183

The last is a parent of the second,

hg log -r 'd14aaf65a80b3baddb19::1c08b566a5c51e7c4f50' -T'{node|short} {desc|firstline}\n'

hg log -r 1c08b566a5c51e7c4f50 -v
changeset:   494183:1c08b566a5c5
parent:      494182:99bfc4e1be4d
parent:      494154:d14aaf65a80b
user:        Daniel Varga <dvarga@mozilla.com>
date:        Tue Sep 04 01:05:40 2018 +0300
files:       devtools/client/debugger/debugger-commands.js devtools/client/inspector/inspector-commands.js devtools/client/responsive.html/commands.js devtools/client/scratchpad/scratchpad-commands.js devtools/client/styleeditor/styleeditor-commands.js devtools/client/webconsole/console-commands.js
description:
Merge mozilla-central to mozilla-inbound

Tested on 4.7.1
Comment 1 Axel Hecht 2018-09-06 04:26 UTC
Created attachment 2019 [details]
test case

I wrote an ancestors iterator for my project, and this is the part of the testcase that I use that demonstrates yielding the parent (0) before the child (1)
Comment 2 Boris Feld 2018-09-06 17:55 UTC
We confirm the issue, we have seen it in other cases. We are working on a patch to fix it.
Comment 3 HG Bot 2018-09-10 11:40 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/b6db2e80a9ce
Boris Feld <boris.feld@octobus.net>
ancestors: actually iterate over ancestors in topological order (issue5979)

This code previously used a dequeue logic, the first ancestors seen were the
first ancestors to be emitted. In branching/merging situations, it can result
in ancestors being yielded before their descendants, breaking the object
contract.

We got affected by this issue while working on the copy tracing code. At about
the same time, Axel Hecht <axel@mozilla.com> reported the issue and provided
the test case used in this changeset. Thanks Axel.

Running `hg perfancestors` does not show a significant difference between the
old and the new version.

(please test the fix)
Comment 4 Bugzilla 2018-09-18 00:00 UTC
Bug was set to TESTING for 7 days, resolving