Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templatefuncs.py @ 37709:7b2955624777
scmutil: make shortesthexnodeidprefix() take a full binary nodeid
The shortest() template function depended on the behavior of
revlog._partialmatch() for these types of inputs:
* non-hex strings
* ambiguous strings
* too long strings
revlog._partialmatch() seems to return the input unchanged in these
cases, but we shouldn't depend on such a low-level function to match
the behavior we want in the user-facing template function. Instead,
let's handle these cases in the template function and always pass a
binary nodeid to _partialmatch().
Differential Revision: https://phab.mercurial-scm.org/D3371
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sat, 14 Apr 2018 00:13:08 -0700 |
parents | 8e8541610d85 |
children | a3b4ccbec269 66dc9db6ed2c |
line wrap: on
line diff
--- a/mercurial/templatefuncs.py Fri Apr 13 10:36:03 2018 -0700 +++ b/mercurial/templatefuncs.py Sat Apr 14 00:13:08 2018 -0700 @@ -10,6 +10,9 @@ import re from .i18n import _ +from .node import ( + bin, +) from . import ( color, encoding, @@ -579,7 +582,7 @@ # i18n: "shortest" is a keyword raise error.ParseError(_("shortest() expects one or two arguments")) - node = evalstring(context, mapping, args[0]) + hexnode = evalstring(context, mapping, args[0]) minlength = 4 if len(args) > 1: @@ -588,6 +591,20 @@ _("shortest() expects an integer minlength")) repo = context.resource(mapping, 'ctx')._repo + if len(hexnode) > 40: + return hexnode + elif len(hexnode) == 40: + try: + node = bin(hexnode) + except TypeError: + return hexnode + else: + try: + node = scmutil.resolvehexnodeidprefix(repo, hexnode) + except (error.LookupError, error.WdirUnsupported): + return hexnode + if not node: + return hexnode return scmutil.shortesthexnodeidprefix(repo, node, minlength) @templatefunc('strip(text[, chars])')