Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templater.py @ 34534:b3073e175c17
templater: wrap get/min/max result so map operation can apply to element
See the test for usage example.
wraphybridvalue() takes a key/value pair because a hybrid dict passes a key
to its makemap() function. Since makemap() of showmanifest() doesn't need
a key, it's set to None.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 09 Sep 2017 19:13:25 +0900 |
parents | a1b89c8ad32d |
children | 78590585c0db |
line wrap: on
line diff
--- a/mercurial/templater.py Mon Oct 02 07:18:24 2017 +0100 +++ b/mercurial/templater.py Sat Sep 09 19:13:25 2017 +0900 @@ -730,7 +730,10 @@ raise error.ParseError(_("get() expects a dict as first argument")) key = evalfuncarg(context, mapping, args[1]) - return dictarg.get(key) + val = dictarg.get(key) + if val is None: + return + return templatekw.wraphybridvalue(dictarg, key, val) @templatefunc('if(expr, then[, else])') def if_(context, mapping, args): @@ -874,10 +877,11 @@ iterable = evalfuncarg(context, mapping, args[0]) try: - return max(iterable) + x = max(iterable) except (TypeError, ValueError): # i18n: "max" is a keyword raise error.ParseError(_("max first argument should be an iterable")) + return templatekw.wraphybridvalue(iterable, x, x) @templatefunc('min(iterable)') def min_(context, mapping, args, **kwargs): @@ -888,10 +892,11 @@ iterable = evalfuncarg(context, mapping, args[0]) try: - return min(iterable) + x = min(iterable) except (TypeError, ValueError): # i18n: "min" is a keyword raise error.ParseError(_("min first argument should be an iterable")) + return templatekw.wraphybridvalue(iterable, x, x) @templatefunc('mod(a, b)') def mod(context, mapping, args):