changeset 42336:604c086ddde6

log: add config for making `hg log -G` always topo-sorted I (and everyone else at Google) have an log alias that adds graph mode and templating. I have another one that builds on the first and also restricts the set of revisions to only show those I'm most likely to care about. This second alias also adds topological sorting. I still sometimes use the first one. When I do, it very often bothers me that it's not topologically sorted (branches are interleaved). This patch adds a config option for always using topological sorting with graph log. The revision set is sorted eagerly, which seems like a bad idea, but it doesn't seem to make a big difference in the hg repo (150ms). I initially tried to instead wrap the user's revset in sort(...,topo), but that seemed much harder. Differential Revision: https://phab.mercurial-scm.org/D6331
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 01 May 2019 09:34:47 -0700
parents 1ce46f0ee218
children 21eda240be07
files mercurial/configitems.py mercurial/logcmdutil.py relnotes/next tests/test-glog-topological.t
diffstat 4 files changed, 57 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/configitems.py	Tue May 14 09:13:39 2019 -0700
+++ b/mercurial/configitems.py	Wed May 01 09:34:47 2019 -0700
@@ -529,6 +529,9 @@
 coreconfigitem('experimental', 'evolution.bundle-obsmarker',
     default=False,
 )
+coreconfigitem('experimental', 'log.topo',
+    default=False,
+)
 coreconfigitem('experimental', 'evolution.report-instabilities',
     default=True,
 )
--- a/mercurial/logcmdutil.py	Tue May 14 09:13:39 2019 -0700
+++ b/mercurial/logcmdutil.py	Wed May 01 09:34:47 2019 -0700
@@ -746,7 +746,12 @@
     if opts.get('graph'):
         # User-specified revs might be unsorted, but don't sort before
         # _makerevset because it might depend on the order of revs
-        if not (revs.isdescending() or revs.istopo()):
+        if repo.ui.configbool('experimental', 'log.topo'):
+            if not revs.istopo():
+                revs = dagop.toposort(revs, repo.changelog.parentrevs)
+                # TODO: try to iterate the set lazily
+                revs = revset.baseset(list(revs))
+        elif not (revs.isdescending() or revs.istopo()):
             revs.sort(reverse=True)
     if expr:
         matcher = revset.match(None, expr)
--- a/relnotes/next	Tue May 14 09:13:39 2019 -0700
+++ b/relnotes/next	Wed May 01 09:34:47 2019 -0700
@@ -3,6 +3,16 @@
  * New config `commands.commit.post-status` shows status after successful
  commit.
 
+
+== New Experimental Features ==
+
+ * New config `experimental.log.topo` makes `hg log -G` use
+   topological sorting. This is especially useful for aliases since it
+   lets the alias accept an `-r` option while still using topological
+   sorting with or without the `-r` (unlike if you use the `sort(...,
+   topo)` revset).
+
+
 == Bug Fixes  ==
 
 
--- a/tests/test-glog-topological.t	Tue May 14 09:13:39 2019 -0700
+++ b/tests/test-glog-topological.t	Wed May 01 09:34:47 2019 -0700
@@ -114,3 +114,41 @@
   |/
   o  0
   
+
+Topological sort can be turned on via config
+
+  $ cat >> $HGRCPATH << EOF
+  > [experimental]
+  > log.topo=true
+  > EOF
+
+  $ hg log -G
+  o  8
+  |
+  o  3
+  |
+  o  2
+  |
+  o  1
+  |
+  | o  7
+  | |
+  | o  6
+  | |
+  | o  5
+  | |
+  | o  4
+  |/
+  o  0
+  
+Does not affect non-graph log
+  $ hg log -T '{rev}\n'
+  8
+  7
+  6
+  5
+  4
+  3
+  2
+  1
+  0