shortest: make {shortest("fffffffff")} work again
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 07 May 2018 09:15:29 -0700
changeset 37859 66dc9db6ed2c
parent 37858 92ed344a9e64
child 37860 a91f31a1e281
shortest: make {shortest("fffffffff")} work again {shortest("fffffffff")} should shorten it to the shortest unambiguous prefix for the working directory. It used to do that until I broke it in 7b2955624777 (scmutil: make shortesthexnodeidprefix() take a full binary nodeid, 2018-04-14), when we started returning the full hex nodeid for any working directory prefix shorter than 40 hex digits. This patch fixes it by catching WdirUnsupported specifically. Differential Revision: https://phab.mercurial-scm.org/D3455
mercurial/templatefuncs.py
tests/test-command-template.t
--- a/mercurial/templatefuncs.py	Sun Apr 29 14:29:09 2018 -0700
+++ b/mercurial/templatefuncs.py	Mon May 07 09:15:29 2018 -0700
@@ -12,6 +12,7 @@
 from .i18n import _
 from .node import (
     bin,
+    wdirid,
 )
 from . import (
     color,
@@ -601,7 +602,9 @@
     else:
         try:
             node = scmutil.resolvehexnodeidprefix(repo, hexnode)
-        except (error.LookupError, error.WdirUnsupported):
+        except error.WdirUnsupported:
+            node = wdirid
+        except error.LookupError:
             return hexnode
         if not node:
             return hexnode
--- a/tests/test-command-template.t	Sun Apr 29 14:29:09 2018 -0700
+++ b/tests/test-command-template.t	Mon May 07 09:15:29 2018 -0700
@@ -3916,6 +3916,15 @@
   $ hg log --template '{shortest("not a hex string, but it'\''s 40 bytes long")}\n' -l1
   not a hex string, but it's 40 bytes long
 
+  $ hg log --template '{shortest("ffffffffffffffffffffffffffffffffffffffff")}\n' -l1
+  ffff
+
+  $ hg log --template '{shortest("fffffff")}\n' -l1
+  ffff
+
+  $ hg log --template '{shortest("ff")}\n' -l1
+  ffff
+
   $ cd ..
 
 Test shortest(node) with the repo having short hash collision: