Patchwork [06,of,10,RFC] templater: teach _flatten about labels

login
register
mail settings
Submitter Sean Farley
Date Dec. 21, 2012, 5:37 a.m.
Message ID <add1ef9a4ea71b3da34b.1356068276@laptop.local>
Download mbox | patch
Permalink /patch/240/
State Superseded
Headers show

Comments

Sean Farley - Dec. 21, 2012, 5:37 a.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1355963949 21600
# Node ID add1ef9a4ea71b3da34b17a0d85307ce80ced92f
# Parent  7db04bb18ded6799e2a8f4d5aa935ded9454c240
templater: teach _flatten about labels

The next order of business for labeling template data is to teach _flatten not to clobber the dictionaries.

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -289,25 +289,27 @@ 
 labelify = templatefilters.labelify
 delabelify = templatefilters.delabelify
 
 def _flatten(thing):
     '''yield a single stream from a possibly nested set of iterators'''
+    thing, label = delabelify(thing)
     if isinstance(thing, str):
-        yield thing
+        yield labelify(thing, label)
     elif not util.safehasattr(thing, '__iter__'):
         if thing is not None:
-            yield str(thing)
+            yield labelify(str(thing), label)
     else:
         for i in thing:
             if isinstance(i, str):
-                yield i
+                yield labelify(i, label)
             elif not util.safehasattr(i, '__iter__'):
                 if i is not None:
-                    yield str(i)
+                    yield labelify(str(i), label)
             elif i is not None:
                 for j in _flatten(i):
-                    yield j
+                    j, j_label = delabelify(j, label)
+                    yield labelify(j, j_label)
 
 def parsestring(s, quoted=True):
     '''parse a string using simple c-like syntax.
     string must be in quotes if quoted is True.'''
     if quoted: