# HG changeset patch # User Weiwen # Date 1354143342 28800 # Node ID e06e9fd2d99ff698c88b7f84b389fb4139b0f461 # Parent 83aa4359c49f67bcb98fb9c7d885ed4ac7443239 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. diff -r 83aa4359c49f -r e06e9fd2d99f mercurial/templater.py --- 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):