Patchwork [2,of,6] templater: inline wraphybridvalue()

login
register
mail settings
Submitter Yuya Nishihara
Date June 8, 2018, 2:51 p.m.
Message ID <ba79741bbadac2e014ee.1528469508@mimosa>
Download mbox | patch
Permalink /patch/32030/
State Accepted
Headers show

Comments

Yuya Nishihara - June 8, 2018, 2:51 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1521601578 -32400
#      Wed Mar 21 12:06:18 2018 +0900
# Node ID ba79741bbadac2e014eec83b6c7b5a6805febc5d
# Parent  9fcd58363baccf1e3f828b64e7cc9d110ff65fb6
templater: inline wraphybridvalue()

All wraphybridvalue() calls are now handled in the hybrid class.

Patch

diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -193,7 +193,10 @@  class hybrid(wrapped):
     def _wrapvalue(self, key, val):
         if val is None:
             return
-        return wraphybridvalue(self, key, val)
+        if util.safehasattr(val, '_makemap'):
+            # a nested hybrid list/dict, which has its own way of map operation
+            return val
+        return mappable(None, key, val, self._makemap)
 
     def itermaps(self, context):
         makemap = self._makemap
@@ -422,20 +425,6 @@  def unwraphybrid(context, mapping, thing
         return thing
     return thing.show(context, mapping)
 
-def wraphybridvalue(container, key, value):
-    """Wrap an element of hybrid container to be mappable
-
-    The key is passed to the makemap function of the given container, which
-    should be an item generated by iter(container).
-    """
-    makemap = getattr(container, '_makemap', None)
-    if makemap is None:
-        return value
-    if util.safehasattr(value, '_makemap'):
-        # a nested hybrid list/dict, which has its own way of map operation
-        return value
-    return mappable(None, key, value, makemap)
-
 def compatdict(context, mapping, name, data, key='key', value='value',
                fmt=None, plural=None, separator=' '):
     """Wrap data like hybriddict(), but also supports old-style list template