D4327: dagop: extract headsetofconnecteds() from dagutil

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Sat Aug 18 04:07:35 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG1c3184d7e882: dagop: extract headsetofconnecteds() from dagutil (authored by indygreg, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D4327?vs=10421&id=10449#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4327?vs=10421&id=10449

REVISION DETAIL
  https://phab.mercurial-scm.org/D4327

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
@@ -10,6 +10,10 @@
 
 from .node import nullrev
 
+from . import (
+    dagop,
+)
+
 class revlogdag(object):
     '''dag interface to a revlog'''
 
@@ -31,21 +35,6 @@
             return [prev2]
         return []
 
-    def headsetofconnecteds(self, ixs):
-        if not ixs:
-            return set()
-        rlog = self._revlog
-        idx = rlog.index
-        headrevs = set(ixs)
-        for rev in ixs:
-            revdata = idx[rev]
-            for i in [5, 6]:
-                prev = revdata[i]
-                if prev != nullrev:
-                    headrevs.discard(prev)
-        assert headrevs
-        return headrevs
-
     def linearize(self, ixs):
         '''linearize and topologically sort a list of revisions
 
@@ -56,7 +45,7 @@
         parent, then adding the rev itself to the output list.
         '''
         sorted = []
-        visit = list(self.headsetofconnecteds(ixs))
+        visit = list(dagop.headrevs(ixs, self.parents))
         visit.sort(reverse=True)
         finished = set()
 
diff --git a/mercurial/dagop.py b/mercurial/dagop.py
--- a/mercurial/dagop.py
+++ b/mercurial/dagop.py
@@ -715,3 +715,26 @@
     for g in groups:
         for r in g[0]:
             yield r
+
+def headrevs(revs, parentsfn):
+    """Resolve the set of heads from a set of revisions.
+
+    Receives an iterable of revision numbers and a callbable that receives a
+    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.
+
+    ``nullrev`` is never included in the returned set, even if it is provided in
+    the input set.
+    """
+    headrevs = set(revs)
+
+    for rev in revs:
+        for prev in parentsfn(rev):
+            headrevs.discard(prev)
+
+    headrevs.discard(node.nullrev)
+
+    return headrevs



To: indygreg, #hg-reviewers
Cc: yuja, mercurial-devel


More information about the Mercurial-devel mailing list