diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -162,8 +162,13 @@ def buildfilter(exp, context): def runfilter(context, mapping, data): func, data, filt = data + # func() may return string, generator of strings or arbitrary object such + # as date tuple, but filter does not want generator. + thing = func(context, mapping, data) + if isinstance(thing, types.GeneratorType): + thing = stringify(thing) try: - return filt(func(context, mapping, data)) + return filt(thing) except (ValueError, AttributeError, TypeError): if isinstance(data, tuple): dt = data[1] 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 @@ -1901,6 +1901,11 @@ Thrown an error if a template function d hg: parse error: unknown function 'foo' [255] +Pass generator object created by template function to filter + + $ hg log -l 1 --template '{if(author, author)|user}\n' + test + Test diff function: $ hg diff -c 8