obshistory: add predecessorsandmarkers()
authorAnton Shestakov <av6@dwimlabs.net>
Fri, 24 Apr 2020 01:14:34 +0800
changeset 5329 0dc4c16506fc
parent 5328 a81631766575
child 5330 0bc31f853862
obshistory: add predecessorsandmarkers()
hgext3rd/evolve/obshistory.py
--- a/hgext3rd/evolve/obshistory.py	Fri Apr 24 01:09:30 2020 +0800
+++ b/hgext3rd/evolve/obshistory.py	Fri Apr 24 01:14:34 2020 +0800
@@ -160,6 +160,34 @@
             groupmarkers.update(markers)
         yield (tuple(sorted(groupnodes)), tuple(sorted(groupmarkers)))
 
+def predecessorsandmarkers(repo, node):
+    """ Compute data needed for obsorigin.
+
+    Return a generator of (nodes, markers) tuples, where nodes is a tuple of
+    predecessor nodes and markers is a tuple of obsolescence markers.
+
+    Using tuples for everything means no problems with sorted().
+    """
+    predecessors = repo.obsstore.predecessors
+    stack = [(node, ())]
+    seen = {node}
+
+    while stack:
+        node, path = stack.pop()
+
+        for marker in sorted(predecessors.get(node, ())):
+            prednode = marker[0]
+
+            # Basic cycle protection
+            if prednode in seen:
+                continue
+            seen.add(prednode)
+
+            if prednode in repo:
+                yield ((prednode,), path + (marker,))
+            else:
+                stack.append((prednode, path + (marker,)))
+
 def _nodesandmarkers(repo, ctx, filternonlocal):
     if filternonlocal:
         r = obsutil.successorsandmarkers(repo, ctx)