dagutil: use revlog.parentrevs() for resolving parent revisions
authorGregory Szorc <gregory.szorc@gmail.com>
Fri, 17 Aug 2018 19:48:52 +0000
changeset 39180 8de526995844
parent 39179 1c3184d7e882
child 39181 0a934ee94f09
dagutil: use revlog.parentrevs() for resolving parent revisions 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. Differential Revision: https://phab.mercurial-scm.org/D4328
mercurial/dagutil.py
--- a/mercurial/dagutil.py	Fri Aug 17 19:45:13 2018 +0000
+++ b/mercurial/dagutil.py	Fri Aug 17 19:48:52 2018 +0000
@@ -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