stablesort: add a 'method' argument to the debugstablesort command
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 23 Nov 2017 16:37:24 +0100
changeset 3246 543708c3f754
parent 3245 63d58f7db120
child 3247 d8e6c5338053
stablesort: add a 'method' argument to the debugstablesort command Let start experimenting with other way to do stable sorting.
hgext3rd/evolve/stablesort.py
tests/test-stablesort-criss-cross.t
tests/test-stablesort.t
--- a/hgext3rd/evolve/stablesort.py	Sat Nov 25 02:58:47 2017 -0500
+++ b/hgext3rd/evolve/stablesort.py	Thu Nov 23 16:37:24 2017 +0100
@@ -12,6 +12,7 @@
 from mercurial import (
     commands,
     cmdutil,
+    error,
     node as nodemod,
     scmutil,
 )
@@ -29,15 +30,24 @@
 @eh.command(
     'debugstablesort',
     [
-        ('', 'rev', [], 'heads to start from'),
+        ('r', 'rev', [], 'heads to start from'),
+        ('', 'method', 'branchpoint', "method used for sorting, one of: 'branchpoint'"),
     ] + commands.formatteropts,
     _(''))
 def debugstablesort(ui, repo, **opts):
     """display the ::REVS set topologically sorted in a stable way
     """
     revs = scmutil.revrange(repo, opts['rev'])
+
+    method = opts['method']
+    sorting = _methodmap.get(method)
+    if sorting is None:
+        valid_method = ', '.join(sorted(_methodmap))
+        raise error.Abort('unknown sorting method: "%s"' % method,
+                          hint='pick one of: %s' % valid_method)
+
     displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
-    for r in stablesort_branchpoint(repo, revs):
+    for r in sorting(repo, revs):
         ctx = repo[r]
         displayer.show(ctx)
         displayer.flush(ctx)
@@ -123,3 +133,7 @@
             stack.extend(cs)   # stack the rest for later
     assert len(result) == len(set(result))
     return result
+
+_methodmap = {
+    'branchpoint': stablesort_branchpoint,
+}
--- a/tests/test-stablesort-criss-cross.t	Sat Nov 25 02:58:47 2017 -0500
+++ b/tests/test-stablesort-criss-cross.t	Thu Nov 23 16:37:24 2017 +0100
@@ -9,7 +9,7 @@
   > [ui]
   > logtemplate = "{rev} {node|short} {desc} {tags}\n"
   > [alias]
-  > showsort = debugstablesort --template="{node|short}\n"
+  > showsort = debugstablesort --template="{node|short}\n" --method branchpoint
   > EOF
 
   $ checktopo () {
--- a/tests/test-stablesort.t	Sat Nov 25 02:58:47 2017 -0500
+++ b/tests/test-stablesort.t	Thu Nov 23 16:37:24 2017 +0100
@@ -9,7 +9,7 @@
   > [ui]
   > logtemplate = "{rev} {node|short} {desc} {tags}\n"
   > [alias]
-  > showsort = debugstablesort --template="{node|short}\n"
+  > showsort = debugstablesort --template="{node|short}\n" --method branchpoint
   > EOF