Patchwork [4,of,5] obsolete: add an allprecursors method mirroring allsuccessors one

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 24, 2013, 12:32 a.m.
Message ID <1677c9118fd971197916.1387845141@marginatus.fb.com>
Download mbox | patch
Permalink /patch/3234/
State Superseded
Headers show

Comments

Pierre-Yves David - Dec. 24, 2013, 12:32 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1387834573 28800
#      Mon Dec 23 13:36:13 2013 -0800
# Node ID 1677c9118fd971197916b7f37177b2a5c03ad802
# Parent  1612cb8211a52d6f19cf1b896a8b138c62ba272a
obsolete: add an allprecursors method mirroring allsuccessors one.

Detection of bumped changeset should use `allprecursors(<mutable>)` instead or
`allsuccessors(<immutable>)` so we need the all precursors function to exists.

Patch

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -454,10 +454,32 @@  def allsuccessors(obsstore, nodes, ignor
             for suc in mark[1]:
                 if suc not in seen:
                     seen.add(suc)
                     remaining.add(suc)
 
+def allprecursors(obsstore, nodes, ignoreflags=0):
+    """Yield node for every precursors of <nodes>.
+
+    Some precursors may be unknown locally.
+
+    This is a linear yield unsuited to detecting folded changesets. It includes
+    initial nodes too."""
+
+    remaining = set(nodes)
+    seen = set(remaining)
+    while remaining:
+        current = remaining.pop()
+        yield current
+        for mark in obsstore.precursors.get(current, ()):
+            # ignore marker flagged with specified flag
+            if mark[2] & ignoreflags:
+                continue
+            suc = mark[0]
+            if suc not in seen:
+                seen.add(suc)
+                remaining.add(suc)
+
 def foreground(repo, nodes):
     """return all nodes in the "foreground" of other node
 
     The foreground of a revision is anything reachable using parent -> children
     or precursor -> successor relation. It is very similar to "descendant" but