[PATCH] revsets: add branchpoint() function

Ivan Andrus darthandrus at gmail.com
Mon Aug 13 16:07:42 CDT 2012


# HG changeset patch
# User Ivan Andrus <darthandrus at gmail.com>
# Date 1344887445 -7200
# Branch stable
# Node ID d3fd1d3ec3a595a7ae08f491bd8ba67c12c3a382
# Parent  96189d60d810317ef8f707ec3ab123a9beb288cd
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.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -909,6 +909,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.
@@ -1464,6 +1483,7 @@
     "bisected": bisected,
     "bookmark": bookmark,
     "branch": branch,
+    "branchpoint": branchpoint,
     "children": children,
     "closed": closed,
     "contains": contains,
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -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


More information about the Mercurial-devel mailing list