Mercurial > hg
changeset 17982:e06e9fd2d99f
template engine: convert generator-based iterator to list-based iterator
If a template iterator is implemented with generator, the iterator is exhau=
sted
after we use it. This leads to undesired behavior in template. This chang=
e
converts a generator-based iterator to list-based iterator when template en=
gine
first detects a generator-based iterator. All future usages of iterator wi=
ll
use list instead.
author | Weiwen <weiwen@fb.com> |
---|---|
date | Wed, 28 Nov 2012 14:55:42 -0800 |
parents | 83aa4359c49f |
children | c64e646af81e |
files | mercurial/templater.py |
diffstat | 1 files changed, 5 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templater.py Wed Nov 28 16:15:05 2012 -0600 +++ b/mercurial/templater.py Wed Nov 28 14:55:42 2012 -0800 @@ -8,6 +8,7 @@ from i18n import _ import sys, os, re import util, config, templatefilters, parser, error +import types # template parsing @@ -140,6 +141,10 @@ v = context._defaults.get(key, '') if util.safehasattr(v, '__call__'): return v(**mapping) + if isinstance(v, types.GeneratorType): + v = list(v) + mapping[key] = v + return v return v def buildfilter(exp, context):