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.
--- 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):