# HG changeset patch # User Pierre-Yves David # Date 1340702026 -7200 # Node ID 8cfa3163dfaa5d45f009f2ef91da1e7bab7ccf68 # Parent 0b444d7c5c96222b6f1e114d5b8eb60101ea77cd obsolete: add precursors and successors revset. diff -r 0b444d7c5c96 -r 8cfa3163dfaa hgext/obsolete.py --- 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 diff -r 0b444d7c5c96 -r 8cfa3163dfaa tests/test-obsolete.t --- 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)