Patchwork [6,of,6] templater: inline unwraphybrid()

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

Comments

Yuya Nishihara - June 8, 2018, 2:51 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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.
Augie Fackler - June 11, 2018, 7:40 p.m.
On Fri, Jun 08, 2018 at 11:51:52PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1521602892 -32400
> #      Wed Mar 21 12:28:12 2018 +0900
> # Node ID 863c2656c97cbfaaf26e0812508e5072d21911cb
> # Parent  1b491a1ed8847e48efad64786c4f09909cce5c5f
> templater: inline unwraphybrid()

queued, thanks

Patch

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: