Submitter | Yuya Nishihara |
---|---|
Date | March 12, 2015, 2:31 p.m. |
Message ID | <f29939bf06ff33ec50a1.1426170719@mimosa> |
Download | mbox | patch |
Permalink | /patch/8020/ |
State | Accepted |
Headers | show |
Comments
On Thu, 2015-03-12 at 23:31 +0900, Yuya Nishihara wrote: > # HG changeset patch > # User Yuya Nishihara <yuya@tcha.org> > # Date 1424703895 -32400 > # Tue Feb 24 00:04:55 2015 +0900 > # Node ID f29939bf06ff33ec50a1647f9048af25ee20a702 > # Parent 7cf9a9e0cf893e7ae82dc576a03c843fd6640438 > templater: allow to pipe generator-type function output to filters Queued for default, thanks.
Patch
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