D4328: dagutil: use revlog.parentrevs() for resolving parent revisions
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Fri Aug 17 21:31:19 UTC 2018
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
And remove parents() since it is no longer used.
revlog.parentrevs() is almost the same as parents(). The main
difference is that parentrevs() can return nullrev. dagop.headrevs()
already handles nullrev. We add an inline check for nullrev in the
other call site to account for the difference.
.. api:: parents() removed from dagutil classes
Use parentrevs() on the storage object instead.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D4328
AFFECTED FILES
mercurial/dagop.py
mercurial/dagutil.py
CHANGE DETAILS
diff --git a/mercurial/dagutil.py b/mercurial/dagutil.py
--- a/mercurial/dagutil.py
+++ b/mercurial/dagutil.py
@@ -20,21 +20,6 @@
def __init__(self, revlog):
self._revlog = revlog
- def parents(self, ix):
- rlog = self._revlog
- idx = rlog.index
- revdata = idx[ix]
- prev = revdata[5]
- if prev != nullrev:
- prev2 = revdata[6]
- if prev2 == nullrev:
- return [prev]
- return [prev, prev2]
- prev2 = revdata[6]
- if prev2 != nullrev:
- return [prev2]
- return []
-
def linearize(self, ixs):
'''linearize and topologically sort a list of revisions
@@ -45,7 +30,7 @@
parent, then adding the rev itself to the output list.
'''
sorted = []
- visit = list(dagop.headrevs(ixs, self.parents))
+ visit = list(dagop.headrevs(ixs, self._revlog.parentrevs))
visit.sort(reverse=True)
finished = set()
@@ -58,7 +43,7 @@
finished.add(cur)
else:
visit.append(-cur - 1)
- visit += [p for p in self.parents(cur)
- if p in ixs and p not in finished]
+ visit += [p for p in self._revlog.parentrevs(cur)
+ if p != nullrev and p in ixs and p not in finished]
assert len(sorted) == len(ixs)
return sorted
diff --git a/mercurial/dagop.py b/mercurial/dagop.py
--- a/mercurial/dagop.py
+++ b/mercurial/dagop.py
@@ -723,13 +723,18 @@
revision number and returns an iterable of parent revision numbers, possibly
including nullrev.
- Returns a set of revision numbers that are DAG heads within the passed subset.
+ Returns a set of revision numbers that are DAG heads within the passed
+ subset.
+
+ ``nullrev`` is never included in the returned set, even if it is provided in
+ the input set.
"""
- headrevs = set()
+ headrevs = set(revs)
for rev in revs:
for prev in parentsfn(rev):
- if prev != node.nullrev:
- headrevs.discard(prev)
+ headrevs.discard(prev)
+
+ headrevs.discard(node.nullrev)
return headrevs
To: indygreg, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list