Mercurial > hg
diff mercurial/formatter.py @ 34425:12bfecd0ffe6
formatter: fix default list/dict generator to be evaluated more than once
Before, _hybrid.gen must be a generator which could be consumed only once.
It was okay in templatekw.py since template keywords are functions which
create temporary hybrid objects, but the formatter doesn't work in that way.
To work around the issue, this patch makes _hybrid.gen optionally be a
function returning a generator.
Thanks to Pulkit for finding this issue.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 01 Oct 2017 08:37:04 +0100 |
parents | ebf2c1b0c70c |
children | f17a0e18c47e |
line wrap: on
line diff
--- a/mercurial/formatter.py Wed Sep 27 21:38:48 2017 +0900 +++ b/mercurial/formatter.py Sun Oct 01 08:37:04 2017 +0100 @@ -348,15 +348,14 @@ data = util.sortdict(_iteritems(data)) def f(): yield _plainconverter.formatdict(data, key, value, fmt, sep) - return templatekw.hybriddict(data, key=key, value=value, fmt=fmt, - gen=f()) + return templatekw.hybriddict(data, key=key, value=value, fmt=fmt, gen=f) @staticmethod def formatlist(data, name, fmt, sep): '''build object that can be evaluated as either plain string or list''' data = list(data) def f(): yield _plainconverter.formatlist(data, name, fmt, sep) - return templatekw.hybridlist(data, name=name, fmt=fmt, gen=f()) + return templatekw.hybridlist(data, name=name, fmt=fmt, gen=f) class templateformatter(baseformatter): def __init__(self, ui, out, topic, opts):