show: pass the minimum length for nodes as a template keyword
authorGregory Szorc <gregory.szorc@gmail.com>
Thu, 03 Aug 2017 21:51:34 -0700
changeset 34190 4441c1113eb2
parent 34189 e9898ad31115
child 34191 e6b5e7329ff2
show: pass the minimum length for nodes as a template keyword This will allow us to make the displayed length configurable and/or dynamic. Differential Revision: https://phab.mercurial-scm.org/D556
hgext/show.py
mercurial/templates/map-cmdline.show
tests/test-show.t
--- a/hgext/show.py	Thu Aug 03 21:13:27 2017 -0700
+++ b/hgext/show.py	Thu Aug 03 21:51:34 2017 -0700
@@ -171,7 +171,8 @@
         fm.write('bookmark', '%s', bm)
         fm.write('node', fm.hexfunc(node), fm.hexfunc(node))
         fm.data(active=bm == active,
-                longestbookmarklen=longestname)
+                longestbookmarklen=longestname,
+                nodelen=5)
 
 @showview('stack', csettopic='stack')
 def showstack(ui, repo, displayer):
@@ -277,7 +278,7 @@
                 ui.write('  ')
 
             ui.write(('o  '))
-            displayer.show(ctx)
+            displayer.show(ctx, nodelen=5)
             displayer.flush(ctx)
             ui.write('\n')
 
@@ -317,7 +318,7 @@
             ui.write('  ')
 
         ui.write(symbol, '  ')
-        displayer.show(ctx)
+        displayer.show(ctx, nodelen=5)
         displayer.flush(ctx)
         ui.write('\n')
 
@@ -334,7 +335,7 @@
         ui.write(_('(stack base)'), '\n', label='stack.label')
         ui.write(('o  '))
 
-        displayer.show(basectx)
+        displayer.show(basectx, nodelen=5)
         displayer.flush(basectx)
         ui.write('\n')
 
@@ -397,7 +398,8 @@
     revdag = graphmod.dagwalker(repo, revs)
 
     ui.setconfig('experimental', 'graphshorten', True)
-    cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges)
+    cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges,
+                         props={'nodelen': 5})
 
 def extsetup(ui):
     # Alias `hg <prefix><view>` to `hg show <view>`.
--- a/mercurial/templates/map-cmdline.show	Thu Aug 03 21:13:27 2017 -0700
+++ b/mercurial/templates/map-cmdline.show	Thu Aug 03 21:51:34 2017 -0700
@@ -3,12 +3,12 @@
 #   piggyback on existing values so color works.
 # * Obsolescence isn't considered for node labels. See _cset_labels in
 #   map-cmdline.default.
-showbookmarks = '{if(active, "*", " ")} {pad(bookmark, longestbookmarklen + 4)}{shortest(node, 5)}\n'
+showbookmarks = '{if(active, "*", " ")} {pad(bookmark, longestbookmarklen + 4)}{shortest(node, nodelen)}\n'
 
 showwork = '{cset_shortnode}{namespaces % cset_namespace} {cset_shortdesc}'
 showstack = '{showwork}'
 
-cset_shortnode = '{label("log.changeset changeset.{phase}", shortest(node, 5))}'
+cset_shortnode = '{label("log.changeset changeset.{phase}", shortest(node, nodelen))}'
 
 # Treat branch and tags specially so we don't display "default" or "tip"
 cset_namespace = '{ifeq(namespace, "branches", names_branches, ifeq(namespace, "tags", names_tags, names_others))}'
--- a/tests/test-show.t	Thu Aug 03 21:13:27 2017 -0700
+++ b/tests/test-show.t	Thu Aug 03 21:51:34 2017 -0700
@@ -112,13 +112,15 @@
     "active": true,
     "bookmark": "a-longer-bookmark",
     "longestbookmarklen": 17,
-    "node": "7b5709ab64cbc34da9b4367b64afff47f2c4ee83"
+    "node": "7b5709ab64cbc34da9b4367b64afff47f2c4ee83",
+    "nodelen": 5
    },
    {
     "active": false,
     "bookmark": "book1",
     "longestbookmarklen": 17,
-    "node": "b757f780b8ffd71267c6ccb32e0882d9d32a8cc0"
+    "node": "b757f780b8ffd71267c6ccb32e0882d9d32a8cc0",
+    "nodelen": 5
    }
   ]