mercurial/templateutil.py
changeset 36920 6ff6e1d6b5b8
parent 36913 da2977e674a3
child 36921 32f9b7e3f056
--- a/mercurial/templateutil.py	Wed Feb 28 15:20:41 2018 -0500
+++ b/mercurial/templateutil.py	Thu Mar 08 23:10:46 2018 +0900
@@ -13,7 +13,6 @@
 from . import (
     error,
     pycompat,
-    templatefilters,
     templatekw,
     util,
 )
@@ -24,6 +23,21 @@
 class TemplateNotFound(error.Abort):
     pass
 
+def stringify(thing):
+    """Turn values into bytes by converting into text and concatenating them"""
+    thing = templatekw.unwraphybrid(thing)
+    if util.safehasattr(thing, '__iter__') and not isinstance(thing, bytes):
+        if isinstance(thing, str):
+            # This is only reachable on Python 3 (otherwise
+            # isinstance(thing, bytes) would have been true), and is
+            # here to prevent infinite recursion bugs on Python 3.
+            raise error.ProgrammingError(
+                'stringify got unexpected unicode string: %r' % thing)
+        return "".join([stringify(t) for t in thing if t is not None])
+    if thing is None:
+        return ""
+    return pycompat.bytestr(thing)
+
 def findsymbolicname(arg):
     """Find symbolic name for the given compiled expression; returns None
     if nothing found reliably"""
@@ -223,5 +237,3 @@
     if val is None:
         return
     return templatekw.wraphybridvalue(dictarg, key, val)
-
-stringify = templatefilters.stringify