Mercurial > hg
changeset 17753:69d5078d760d
revsets: add branchpoint() function
The branchpoint() function returns changesets with more than one child.
Eventually I would like to be able to see only branch points and merge
points in a graphical log to see the topology of the repository.
author | Ivan Andrus <darthandrus@gmail.com> |
---|---|
date | Mon, 13 Aug 2012 21:50:45 +0200 |
parents | 76b73ce0ffac |
children | 19e9bf7c0927 |
files | mercurial/revset.py tests/test-revset.t |
diffstat | 2 files changed, 30 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revset.py Thu Oct 11 22:58:34 2012 -0500 +++ b/mercurial/revset.py Mon Aug 13 21:50:45 2012 +0200 @@ -918,6 +918,25 @@ cl = repo.changelog return [r for r in subset if cl.parentrevs(r)[1] != -1] +def branchpoint(repo, subset, x): + """``branchpoint()`` + Changesets with more than one child. + """ + # i18n: "branchpoint" is a keyword + getargs(x, 0, 0, _("branchpoint takes no arguments")) + cl = repo.changelog + if not subset: + return [] + baserev = min(subset) + parentscount = [0]*(len(repo) - baserev) + for r in xrange(baserev + 1, len(repo)): + for p in cl.parentrevs(r): + if p >= baserev: + parentscount[p - baserev] += 1 + branchpoints = set((baserev + i) for i in xrange(len(parentscount)) + if parentscount[i] > 1) + return [r for r in subset if r in branchpoints] + def minrev(repo, subset, x): """``min(set)`` Changeset with lowest revision number in set. @@ -1474,6 +1493,7 @@ "bisected": bisected, "bookmark": bookmark, "branch": branch, + "branchpoint": branchpoint, "children": children, "closed": closed, "contains": contains,
--- a/tests/test-revset.t Thu Oct 11 22:58:34 2012 -0500 +++ b/tests/test-revset.t Mon Aug 13 21:50:45 2012 +0200 @@ -332,6 +332,9 @@ 0 $ log 'merge()' 6 + $ log 'branchpoint()' + 1 + 4 $ log 'modifies(b)' 4 $ log 'modifies("path:b")' @@ -362,6 +365,13 @@ $ log 'parents(merge())' 4 5 + $ log 'p1(branchpoint())' + 0 + 2 + $ log 'p2(branchpoint())' + $ log 'parents(branchpoint())' + 0 + 2 $ log 'removes(a)' 2 6