Patchwork [5,of,5] topoiter: allow to select what the first branch should be

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 18, 2014, 11:56 p.m.
Message ID <5c32d4c08a85c3e9b133.1416354971@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6783/
State Superseded
Headers show

Comments

Pierre-Yves David - Nov. 18, 2014, 11:56 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1409851697 -7200
#      Thu Sep 04 19:28:17 2014 +0200
# Node ID 5c32d4c08a85c3e9b133200bee9bfa17b66eeec1
# Parent  026932aa1c4f05cf930c5853ae894636399de111
topoiter: 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.

Patch

diff --git a/mercurial/graphmod.py b/mercurial/graphmod.py
--- a/mercurial/graphmod.py
+++ b/mercurial/graphmod.py
@@ -22,18 +22,16 @@  import util
 
 import heapq
 
 CHANGESET = 'C'
 
-def topoiter(revs, parentsfunc):
+def topoiter(revs, parentsfunc, firstbranch=()):
     """topologically iter over a set of revision, one branch at a time.
 
     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.
-
     The revision are emitted heads to roots."""
     ### Quick summary of the algorithm
     #
     # This function is based around a "retention" principle. We keep revision
     # in memory until we are ready to emit a whole branch that immediately
@@ -59,14 +57,20 @@  def topoiter(revs, parentsfunc):
     #
     # To bootstrap the algorithm, we display the first revision we saw.
 
     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()
+    # set of revision whose children should be considered read to be outputed:
+    #
+    # This is filled with the 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.
+    #
+    # if someone wants to prioritize a branch over the others, pre-filling this
+    # set will force all other branch 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 the sets)
@@ -212,11 +216,16 @@  def dagwalker(repo, revs):
     cl = repo.changelog
     lowestrev = revs.min()
     gpcache = {}
 
     if repo.ui.configbool('experimental', 'graph-topological', False):
-        revs = list(topoiter(revs, repo.changelog.parentrevs))
+        firstbranch = ()
+        firstbranchrevset = repo.ui.config('experimental',
+                                           'graph-topological.firstbranch', '')
+        if firstbranchrevset:
+            firstbranch = repo.revs(firstbranchrevset)
+        revs = list(topoiter(revs, repo.changelog.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
+