diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -350,6 +350,7 @@ def stringify(thing): """Any type. Turns the value into text by converting values into text and concatenating them. """ + thing = templatekw.unwraphybrid(thing) if util.safehasattr(thing, '__iter__') and not isinstance(thing, str): return "".join([stringify(t) for t in thing if t is not None]) if thing is None: diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -35,8 +35,6 @@ class _hybrid(object): self.values = values self._makemap = makemap self.joinfmt = joinfmt - def __iter__(self): - return self.gen def itermaps(self): makemap = self._makemap for x in self.values: @@ -50,6 +48,13 @@ class _hybrid(object): raise AttributeError(name) return getattr(self.values, name) +def unwraphybrid(thing): + """Return an object which can be stringified possibly by using a legacy + template""" + if not util.safehasattr(thing, 'gen'): + return thing + return thing.gen + def showlist(name, values, plural=None, element=None, separator=' ', **args): if not element: element = name diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -1020,6 +1020,7 @@ stringify = templatefilters.stringify def _flatten(thing): '''yield a single stream from a possibly nested set of iterators''' + thing = templatekw.unwraphybrid(thing) if isinstance(thing, str): yield thing elif thing is None: @@ -1028,6 +1029,7 @@ def _flatten(thing): yield str(thing) else: for i in thing: + i = templatekw.unwraphybrid(i) if isinstance(i, str): yield i elif i is None: