[PATCH 5 of 5 V2] groupbranchiter: allow to select what the first branch should be

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Dec 2 11:29:26 CST 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1409851697 -7200
#      Thu Sep 04 19:28:17 2014 +0200
# Node ID c57d59838e60b547005ac6ae2b304159eb218a09
# Parent  d9e86be59f0365deeca01edc76c0c4aca03fe06d
groupbranchiter: allow to select what the first branch should be

Instead of just bootstrap the algorithm with the first revision we see, we allow
to pass revs that should be displayed first. All branches are retained until we
can display such revision.

Expected usage it to display the current working copy parent first.

diff --git a/mercurial/graphmod.py b/mercurial/graphmod.py
--- a/mercurial/graphmod.py
+++ b/mercurial/graphmod.py
@@ -22,11 +22,11 @@ import util
 
 import heapq
 
 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 at being used by graph generator that wish to minimise
     the amount of parallel branches and their interleaving.
 
@@ -42,12 +42,12 @@ def groupbranchiter(revs, parentsfunc):
       |/
       o  0
 
     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
     # in memory until we are ready to emit a whole branch that immediately
     # "merge" into an existing one. This reduce the number of branch "ongoing"
@@ -76,11 +76,15 @@ def groupbranchiter(revs, parentsfunc):
     revs.sort(reverse=True)
 
     # 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:
     #
     #   (revs:    lists of revs waiting to be displayed,
     #    blocked: set of that cannot be displayed before those in 'revs')
@@ -222,11 +226,17 @@ def dagwalker(repo, revs):
     cl = repo.changelog
     lowestrev = revs.min()
     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]
         parents = sorted(set([p.rev() for p in ctx.parents()
                               if p.rev() in revs]))
diff --git a/tests/test-glog-topological.t b/tests/test-glog-topological.t
--- a/tests/test-glog-topological.t
+++ b/tests/test-glog-topological.t
@@ -76,5 +76,26 @@ later.
   | o  4
   |/
   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
+  


More information about the Mercurial-devel mailing list