diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -28,6 +28,7 @@ class _hybrid(object): and to access raw values: - "{ifcontains(file, files, ...)}", "{ifcontains(key, extras, ...)}" - "{get(extras, key)}" + - "{files|json}" """ def __init__(self, gen, values, makemap, joinfmt): @@ -43,8 +44,11 @@ class _hybrid(object): return x in self._values def __len__(self): return len(self._values) + def __iter__(self): + return iter(self._values) def __getattr__(self, name): - if name != 'get': + if name not in ('get', 'items', 'iteritems', 'iterkeys', 'itervalues', + 'keys', 'values'): raise AttributeError(name) return getattr(self._values, name) diff --git a/tests/test-command-template.t b/tests/test-command-template.t --- a/tests/test-command-template.t +++ b/tests/test-command-template.t @@ -3392,6 +3392,13 @@ Test get function: hg: parse error: get() expects a dict as first argument [255] +Test json filter applied to hybrid object: + + $ hg log -r0 -T '{files|json}\n' + ["a"] + $ hg log -r0 -T '{extras|json}\n' + {"branch": "default"} + Test localdate(date, tz) function: $ TZ=JST-09 hg log -r0 -T '{date|localdate|isodate}\n'