changeset 306:8cfa3163dfaa

obsolete: add precursors and successors revset.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Tue, 26 Jun 2012 11:13:46 +0200
parents 0b444d7c5c96
children 9ac56d36d6ff
files hgext/obsolete.py tests/test-obsolete.t
diffstat 2 files changed, 58 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/obsolete.py	Tue Jun 26 11:11:52 2012 +0200
+++ b/hgext/obsolete.py	Tue Jun 26 11:13:46 2012 +0200
@@ -215,6 +215,51 @@
     cs = _allprecursors(repo, s)
     return [r for r in subset if r in cs]
 
+def _successors(repo, s):
+    """Successors of a changeset"""
+    cs = set()
+    nm = repo.changelog.nodemap
+    markerbyobj = repo.obsoletestore.objects
+    for r in s:
+        for p in markerbyobj.get(repo[r].node(), ()):
+            for sub in p['subjects']:
+                sr = nm.get(sub)
+                if sr is not None:
+                    cs.add(sr)
+    return cs
+
+def revsetsuccessors(repo, subset, x):
+    """successors of a subset"""
+    s = revset.getset(repo, range(len(repo)), x)
+    cs = _successors(repo, s)
+    return [r for r in subset if r in cs]
+
+def _allsuccessors(repo, s):  # XXX we need a better naming
+    """transitive successors of a subset"""
+    toproceed = [repo[r].node() for r in s]
+    seen = set()
+    allobjects = repo.obsoletestore.objects
+    while toproceed:
+        nc = toproceed.pop()
+        for mark in allobjects.get(nc, ()):
+            for sub in mark['subjects']:
+                if sub not in seen:
+                    seen.add(sub)
+                    toproceed.append(sub)
+    nm = repo.changelog.nodemap
+    cs = set()
+    for s in seen:
+        sr = nm.get(s)
+        if sr is not None:
+            cs.add(sr)
+    return cs
+
+def revsetallsuccessors(repo, subset, x):
+    """obsolete parents"""
+    s = revset.getset(repo, range(len(repo)), x)
+    cs = _allsuccessors(repo, s)
+    return [r for r in subset if r in cs]
+
 
 ### template keywords
 #####################
@@ -326,6 +371,8 @@
     revset.symbols["precursors"] = revsetprecursors
     revset.symbols["obsancestors"] = revsetallprecursors  # DEPR
     revset.symbols["allprecursors"] = revsetallprecursors  # bad name
+    revset.symbols["successors"] = revsetsuccessors
+    revset.symbols["allsuccessors"] = revsetallsuccessors  # bad name
 
     templatekw.keywords['obsolete'] = obsoletekw
 
--- a/tests/test-obsolete.t	Tue Jun 26 11:11:52 2012 +0200
+++ b/tests/test-obsolete.t	Tue Jun 26 11:13:46 2012 +0200
@@ -72,6 +72,12 @@
   @@ -0,0 +1,1 @@
   +obsol_c
 
+Test that obsolete successors a properly computed
+
+  $ qlog -r 'successors(2)' --hidden
+  3
+  - 0d3f46688ccc
+
 test obsolete changeset with no-obsolete descendant
   $ hg up 1 -q
   $ mkcommit "obsol_c'" # 4 (on 1)
@@ -94,6 +100,11 @@
   - 4538525df7e2
   3
   - 0d3f46688ccc
+  $ qlog -r 'allsuccessors(2)' --hidden
+  3
+  - 0d3f46688ccc
+  4
+  - 725c380fe99b
   $ hg up 3 -q
   Working directory parent is obsolete
   $ mkcommit d # 5 (on 3)