changelog: use Rust RevlogIndex for ancestors

Reviewed By: DurhamG

Differential Revision: D22402199

fbshipit-source-id: cf8354fe41224e3e5dea90508ed7fe473f3a6b08
This commit is contained in:
Jun Wu 2020-07-17 22:22:03 -07:00 committed by Facebook GitHub Bot
parent e6c9e6aa42
commit 01a6a189c6
5 changed files with 27 additions and 16 deletions

View File

@ -884,6 +884,23 @@ class changelog(revlog.revlog):
else:
return super(changelog, self)._partialmatch(hexprefix)
def ancestors(self, revs, stoprev=0, inclusive=False):
"""Return ::revs (in revs) if inclusive is True.
If inclusive is False, return ::parents(revs).
If stoprev is not zero, filter the result.
stoprev is ignored in the Rust implementation.
"""
if self.userust("ancestors"):
nodes = self.tonodes(revs)
dag = self.dag
if not inclusive:
nodes = dag.parents(nodes)
ancestornodes = dag.ancestors(nodes)
return self.torevs(ancestornodes)
else:
return super(changelog, self).ancestors(revs, stoprev, inclusive)
def readfiles(text):
# type: (bytes) -> List[str]

View File

@ -303,6 +303,7 @@ coreconfigitem("experimental", "remotenames", default=False)
# load Rust-based HgCommits on changelog.
coreconfigitem("experimental", "rust-commits", default=util.istest())
coreconfigitem("experimental", "rust-commits:ancestor", default=True)
coreconfigitem("experimental", "rust-commits:ancestors", default=True)
coreconfigitem("experimental", "rust-commits:children", default=True)
coreconfigitem("experimental", "rust-commits:descendants", default=True)
coreconfigitem("experimental", "rust-commits:findcommonmissing", default=True)

View File

@ -252,25 +252,24 @@ def test_gca():
for i, (dag, tests) in enumerate(dagtests):
repo = hg.repository(u, "gca%d" % i, create=1)
cl = repo.changelog
if not util.safehasattr(cl.index, "ancestors"):
# C version not available
return
torevs = cl.torevs
tonodes = cl.tonodes
debugcommands.debugbuilddag(u, repo, dag)
# Compare the results of the Python and C versions. This does not
# include choosing a winner when more than one gca exists -- we make
# sure both return exactly the same set of gcas.
# Also compare against expected results, if available.
for a in cl:
for b in cl:
cgcas = sorted(cl.index.ancestors(a, b))
rsgcas = sorted(torevs(cl.dag.gcaall(tonodes([a, b]))))
pygcas = sorted(ancestor.ancestors(cl.parentrevs, a, b))
expected = None
if (a, b) in tests:
expected = tests[(a, b)]
if cgcas != pygcas or (expected and cgcas != expected):
if rsgcas != pygcas or (expected and rsgcas != expected):
print("test_gca: for dag %s, gcas for %d, %d:" % (dag, a, b))
print(" C returned: %s" % cgcas)
print(" Rust returned: %s" % rsgcas)
print(" Python returned: %s" % pygcas)
if expected:
print(" expected: %s" % expected)

View File

@ -68,10 +68,6 @@ if __name__ == "__main__":
for r in repo.changelog.ancestors([5, 4]):
print(r, end=" ")
print("\nAncestors of 7, stop at 6")
for r in repo.changelog.ancestors([7], 6):
print(r, end=" ")
print("\nAncestors of 7, including revs")
for r in repo.changelog.ancestors([7], inclusive=True):
print(r, end=" ")

View File

@ -1,15 +1,13 @@
Ancestors of 5
4 2 0
Ancestors of 6 and 5
3 4 2 1 0
4 3 2 1 0
Ancestors of 5 and 4
4 2 0
Ancestors of 7, stop at 6
6
Ancestors of 7, including revs
7 6 5 3 4 2 1 0
7 6 5 4 3 2 1 0
Ancestors of 7, 5 and 3, including revs
7 5 3 6 4 2 1 0
7 6 5 4 3 2 1 0
Descendants of 5
7 8