[PATCH V2] graph: support the branch grouping experiment from mercurial core

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon Dec 22 23:40:51 UTC 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1412190676 18000
#      Wed Oct 01 14:11:16 2014 -0500
# Node ID 3e89da86b45922fd4c338b902ae7b56b7c8112dc
# Parent  b31d00b4f989f8bce28c92c319e05e06c4024376
graph: support the branch grouping experiment from mercurial core

Mercurial now have some experimental feature to display node of the graph branch
by branch. This patch add the small logic necessary to honor the config option
to opt in this experiment.

I've been using it for two months without major bug (some issue with the
"source" graph, but nothing major).

diff --git a/tortoisehg/hgqt/graph.py b/tortoisehg/hgqt/graph.py
--- a/tortoisehg/hgqt/graph.py
+++ b/tortoisehg/hgqt/graph.py
@@ -217,10 +217,17 @@ import os
 import itertools
 import collections
 
 from mercurial import revset as revsetmod
 from mercurial import phases
+try:
+    from mercurial.graphmod import groupbranchiter
+except ImportError:
+    # for hg<3.3
+    def groupbranchiter(revs, *args, **kwargs):
+        """dummy function doing nothing for old version"""
+        return revs
 
 from tortoisehg.util import obsoleteutil
 
 LINE_TYPE_PARENT = 0
 LINE_TYPE_FAMILY = 1
@@ -279,11 +286,24 @@ class StandardDag(object):
         curr_rev = self.start_rev
         if curr_rev is None:
             if visiblerev(curr_rev):
                 yield repo[curr_rev]
             curr_rev = len(repo) - 1
-        for curr_rev in revsetmod.spanset(repo, curr_rev, stop_rev - 1):
+        revs = revsetmod.spanset(repo, curr_rev, stop_rev - 1)
+        # jump in the branch grouping graph experiment if the user subscribed
+        if repo.ui.configbool('experimental', 'graph-group-branches', False):
+            revs = list(groupbranchiter(revs, repo.changelog.parentrevs))
+            firstbranch = ()
+            firstbranchrevset = repo.ui.config('experimental',
+                                               'graph-group-branches.firstbranch',
+                                               '')
+            if firstbranchrevset:
+                firstbranch = repo.revs(firstbranchrevset)
+            parentrevs = repo.changelog.parentrevs
+            revs = list(groupbranchiter(revs, parentrevs, firstbranch))
+
+        for curr_rev in revs:
             if visiblerev(curr_rev):
                 yield repo[curr_rev]
 
     def _append_graft_source(self, ctx, parents):
         src_rev_str = ctx.extra().get('source')


More information about the Mercurial-devel mailing list