Patchwork D6331: log: add config for making `hg log -G` always topo-sorted

login
register
mail settings
Submitter phabricator
Date May 15, 2019, 6:31 p.m.
Message ID <75d36a1cd06a00e8982bd11f72a319e5@localhost.localdomain>
Download mbox | patch
Permalink /patch/40069/
State Not Applicable
Headers show

Comments

phabricator - May 15, 2019, 6:31 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGa39f8aa64cef: log: add config for making `hg log -G` always topo-sorted (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6331?vs=15076&id=15122

REVISION DETAIL
  https://phab.mercurial-scm.org/D6331

AFFECTED FILES
  mercurial/configitems.py
  mercurial/logcmdutil.py
  relnotes/next
  tests/test-glog-topological.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers, pulkit
Cc: marmoute, yuja, mjpieters, mercurial-devel

Patch

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
@@ -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
diff --git a/relnotes/next b/relnotes/next
--- a/relnotes/next
+++ b/relnotes/next
@@ -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  ==
 
 
diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -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)
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -529,6 +529,9 @@ 
 coreconfigitem('experimental', 'evolution.bundle-obsmarker',
     default=False,
 )
+coreconfigitem('experimental', 'log.topo',
+    default=False,
+)
 coreconfigitem('experimental', 'evolution.report-instabilities',
     default=True,
 )