shortest: use 'x' prefix to disambiguate from revnum if configured
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 16 Apr 2018 23:49:38 -0700
changeset 38856 a01200b25da6
parent 38855 7848f284b211
child 38857 96d0795bd0bd
shortest: use 'x' prefix to disambiguate from revnum if configured Differential Revision: https://phab.mercurial-scm.org/D4042
mercurial/scmutil.py
tests/test-template-functions.t
--- a/mercurial/scmutil.py	Sun Apr 29 10:07:40 2018 -0700
+++ b/mercurial/scmutil.py	Mon Apr 16 23:49:38 2018 -0700
@@ -490,6 +490,12 @@
 
     def disambiguate(prefix):
         """Disambiguate against revnums."""
+        if repo.ui.configbool('experimental', 'revisions.prefixhexnode'):
+            if mayberevnum(repo, prefix):
+                return 'x' + prefix
+            else:
+                return prefix
+
         hexnode = hex(node)
         for length in range(len(prefix), len(hexnode) + 1):
             prefix = hexnode[:length]
--- a/tests/test-template-functions.t	Sun Apr 29 10:07:40 2018 -0700
+++ b/tests/test-template-functions.t	Mon Apr 16 23:49:38 2018 -0700
@@ -892,6 +892,11 @@
   $ hg log -r 4 -T '{rev}:{shortest(node, 0)}\n' --hidden
   4:107
 
+  $ hg --config experimental.revisions.prefixhexnode=yes log -r 4 -T '{rev}:{shortest(node, 0)}\n'
+  4:x10
+  $ hg --config experimental.revisions.prefixhexnode=yes log -r 4 -T '{rev}:{shortest(node, 0)}\n' --hidden
+  4:x10
+
  node 'c562' should be unique if the other 'c562' nodes are hidden
  (but we don't try the slow path to filter out hidden nodes for now)