groupbranchiter: allow callers to select the first branch
Instead of just bootstrapping the algorithm with the first revision we
see, allow callers to pass revs that should be displayed first. All
branches are retained until we can display such revision.
Expected usage is to display the current working copy parent first.
--- a/mercurial/graphmod.py Thu Sep 04 19:05:36 2014 +0200
+++ b/mercurial/graphmod.py Thu Sep 04 19:28:17 2014 +0200
@@ -24,7 +24,7 @@
CHANGESET = 'C'
-def groupbranchiter(revs, parentsfunc):
+def groupbranchiter(revs, parentsfunc, firstbranch=()):
"""yield revision from heads to roots one (topo) branch after the other.
This function aims to be used by a graph generator that wishes to minimize
@@ -44,8 +44,8 @@
Currently consider every changeset under a merge to be on the same branch
using revision number to sort them.
+ """
- Could be easily extend to give priority to an initial branch."""
### Quick summary of the algorithm
#
# This function is based around a "retention" principle. We keep revisions
@@ -78,7 +78,11 @@
# Set of parents of revision that have been yield. They can be considered
# unblocked as the graph generator is already aware of them so there is no
# need to delay the one that reference them.
- unblocked = set()
+ #
+ # If someone wants to prioritize a branch over the others, pre-filling this
+ # set will force all other branches to wait until this branch is ready to be
+ # outputed.
+ unblocked = set(firstbranch)
# list of group waiting to be displayed, each group is defined by:
#
@@ -224,7 +228,13 @@
gpcache = {}
if repo.ui.configbool('experimental', 'graph-topological', False):
- revs = list(groupbranchiter(revs, repo.changelog.parentrevs))
+ firstbranch = ()
+ firstbranchrevset = repo.ui.config('experimental',
+ 'graph-topological.firstbranch', '')
+ if firstbranchrevset:
+ firstbranch = repo.revs(firstbranchrevset)
+ parentrevs = repo.changelog.parentrevs
+ revs = list(groupbranchiter(revs, parentrevs, firstbranch))
for rev in revs:
ctx = repo[rev]
--- a/tests/test-glog-topological.t Thu Sep 04 19:05:36 2014 +0200
+++ b/tests/test-glog-topological.t Thu Sep 04 19:28:17 2014 +0200
@@ -78,3 +78,24 @@
o 0
+(begin) from the other branch
+
+ $ hg --config experimental.graph-topological=1 --config experimental.graph-topological.firstbranch=5 log -G
+ o 7
+ |
+ o 6
+ |
+ o 5
+ |
+ o 4
+ |
+ | o 8
+ | |
+ | o 3
+ | |
+ | o 2
+ | |
+ | o 1
+ |/
+ o 0
+