[PATCH 6 of 6] templater: inline unwraphybrid()

Yuya Nishihara yuya at tcha.org
Fri Jun 8 10:51:52 EDT 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1521602892 -32400
#      Wed Mar 21 12:28:12 2018 +0900
# Node ID 863c2656c97cbfaaf26e0812508e5072d21911cb
# Parent  1b491a1ed8847e48efad64786c4f09909cce5c5f
templater: inline unwraphybrid()

flatten() is the solo user of this function.

diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -31,8 +31,7 @@ class wrapped(object):
     """Object requiring extra conversion prior to displaying or processing
     as value
 
-    Use unwrapvalue(), unwrapastype(), or unwraphybrid() to obtain the inner
-    object.
+    Use unwrapvalue() or unwrapastype() to obtain the inner object.
     """
 
     __metaclass__ = abc.ABCMeta
@@ -434,13 +433,6 @@ def hybridlist(data, name, fmt=None, gen
         prefmt = pycompat.bytestr
     return hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % prefmt(x))
 
-def unwraphybrid(context, mapping, thing):
-    """Return an object which can be stringified possibly by using a legacy
-    template"""
-    if not isinstance(thing, wrapped):
-        return thing
-    return thing.show(context, mapping)
-
 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
@@ -534,7 +526,8 @@ def _showcompatlist(context, mapping, na
 
 def flatten(context, mapping, thing):
     """Yield a single stream from a possibly nested set of iterators"""
-    thing = unwraphybrid(context, mapping, thing)
+    if isinstance(thing, wrapped):
+        thing = thing.show(context, mapping)
     if isinstance(thing, bytes):
         yield thing
     elif isinstance(thing, str):
@@ -548,7 +541,8 @@ def flatten(context, mapping, thing):
         yield pycompat.bytestr(thing)
     else:
         for i in thing:
-            i = unwraphybrid(context, mapping, i)
+            if isinstance(i, wrapped):
+                i = i.show(context, mapping)
             if isinstance(i, bytes):
                 yield i
             elif i is None:


More information about the Mercurial-devel mailing list