Add a bosancestors revset
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 08 Mar 2012 14:15:53 +0100
changeset 144 f387658d6d22
parent 143 0599fb01dc41
child 145 928f217c1701
Add a bosancestors revset
hgext/obsolete.py
tests/test-obsolete.t
--- a/hgext/obsolete.py	Thu Mar 08 13:56:27 2012 +0100
+++ b/hgext/obsolete.py	Thu Mar 08 14:15:53 2012 +0100
@@ -135,7 +135,8 @@
     return [r for r in subset if r in repo._extinctset]
 
 
-def _obsparents(repo, narrow, s):
+def _obsparents(repo, s):
+    """obsolete parents of a subset"""
     cs = set()
     nm = repo.changelog.nodemap
     for r in s:
@@ -145,13 +146,38 @@
                 cs.add(pr)
     return cs
 
+def revsetobsparents(repo, subset, x):
+    """obsolete parents"""
+    s = revset.getset(repo, range(len(repo)), x)
+    cs = _obsparents(repo, s)
+    return [r for r in subset if r in cs]
 
-def revsetobsparents(repo, subset, x):
-    """obsolete parents of a changeset"""
+def _obsancestors(repo, s):
+    """obsolete ancestors of a subset"""
+    toproceed = [repo[r].node() for r in s]
+    seen = set()
+    while toproceed:
+        nc = toproceed.pop()
+        for np in repo._obssubrels.get(nc, ()):
+            if np not in seen:
+                seen.add(np)
+                toproceed.append(np)
+    nm = repo.changelog.nodemap
+    cs = set()
+    for p in seen:
+        pr = nm.get(p, None)
+        if pr is not None:
+            cs.add(pr)
+    return cs
+
+def revsetobsancestors(repo, subset, x):
+    """obsolete parents"""
     s = revset.getset(repo, range(len(repo)), x)
-    cs = _obsparents(repo, subset, s)
+    cs = _obsancestors(repo, s)
     return [r for r in subset if r in cs]
 
+
+
 ### Other Extension compat
 ############################
 
@@ -179,6 +205,7 @@
     revset.symbols["suspended"] = revsetsuspended
     revset.symbols["extinct"] = revsetextinct
     revset.symbols["obsparents"] = revsetobsparents
+    revset.symbols["obsancestors"] = revsetobsancestors
 
 
     try:
--- a/tests/test-obsolete.t	Thu Mar 08 13:56:27 2012 +0100
+++ b/tests/test-obsolete.t	Thu Mar 08 14:15:53 2012 +0100
@@ -90,6 +90,11 @@
   - 4538525df7e2
   3
   - 0d3f46688ccc
+  $ qlog -r 'obsancestors(4)' --hidden
+  2
+  - 4538525df7e2
+  3
+  - 0d3f46688ccc
   $ hg up 3 -q
   Working directory parent is obsolete
   $ mkcommit d # 5 (on 3)