# HG changeset patch # User Yuya Nishihara # Date 1424269072 -32400 # Node ID e7baf88c29c32dcc8446301fff4c77038f241694 # Parent bd504d90588d58938005b581667cae53b6d22fb8 templatekw: forward _hybrid.get to raw values so that get(extras, key) works ef78450c8df6 implies that the primary goal is to allow "{get(extras, key)}", but it didn't work. I'm not sure if _hybrid should forward all unknown attributes to values, so only "get" is forwarded for now. diff -r bd504d90588d -r e7baf88c29c3 mercurial/templatekw.py --- a/mercurial/templatekw.py Wed Feb 18 23:01:33 2015 +0900 +++ b/mercurial/templatekw.py Wed Feb 18 23:17:52 2015 +0900 @@ -14,6 +14,7 @@ # "{files % '{file}\n'}" (hgweb-style with inlining and function support) # and to access raw values: # "{ifcontains(file, files, ...)}", "{ifcontains(key, extras, ...)}" +# "{get(extras, key)}" class _hybrid(object): def __init__(self, gen, values, makemap, joinfmt=None): @@ -34,6 +35,10 @@ return x in self.values def __len__(self): return len(self.values) + def __getattr__(self, name): + if name != 'get': + raise AttributeError(name) + return getattr(self.values, name) def showlist(name, values, plural=None, element=None, **args): if not element: diff -r bd504d90588d -r e7baf88c29c3 tests/test-command-template.t --- a/tests/test-command-template.t Wed Feb 18 23:01:33 2015 +0900 +++ b/tests/test-command-template.t Wed Feb 18 23:17:52 2015 +0900 @@ -2286,6 +2286,14 @@ $ hg log -r 0 --template '{if(branches, "yes", "no")}\n' no +Test get function: + + $ hg log -r 0 --template '{get(extras, "branch")}\n' + default + $ hg log -r 0 --template '{get(files, "should_fail")}\n' + hg: parse error: get() expects a dict as first argument + [255] + Test shortest(node) function: $ echo b > b