Pierre-Yves David avatar Pierre-Yves David committed 8cfa316

obsolete: add precursors and successors revset.

Comments (0)

Files changed (2)

hgext/obsolete.py

     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
 #####################
     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
 

tests/test-obsolete.t

   @@ -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)
   - 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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.