diff mercurial/templater.py @ 28373:9a9dd71e882c

templater: make label() take unknown symbol as color literal Instead of the mapping hack introduced by b775a2029e8d, this patch changes the way how a label symbol is evaluated. This is still hackish, but should be more predictable in that it doesn't depend on the known color effects. This change is intended to eliminate the reference to color._effects so that color.templatelabel() can be merged with templater.label().
author Yuya Nishihara <yuya@tcha.org>
date Thu, 11 Jun 2015 22:58:27 +0900
parents 7cb2f2438f85
children af3bd9d1dbc1
line wrap: on
line diff
--- a/mercurial/templater.py	Wed Mar 02 15:50:34 2016 +0000
+++ b/mercurial/templater.py	Thu Jun 11 22:58:27 2015 +0900
@@ -231,6 +231,16 @@
     func, data = arg
     return stringify(func(context, mapping, data))
 
+def evalstringliteral(context, mapping, arg):
+    """Evaluate given argument as string template, but returns symbol name
+    if it is unknown"""
+    func, data = arg
+    if func is runsymbol:
+        thing = func(context, mapping, data, default=data)
+    else:
+        thing = func(context, mapping, data)
+    return stringify(thing)
+
 def runinteger(context, mapping, data):
     return int(data)
 
@@ -245,7 +255,7 @@
 def _runrecursivesymbol(context, mapping, key):
     raise error.Abort(_("recursive reference '%s' in template") % key)
 
-def runsymbol(context, mapping, key):
+def runsymbol(context, mapping, key, default=''):
     v = mapping.get(key)
     if v is None:
         v = context._defaults.get(key)
@@ -257,7 +267,7 @@
         try:
             v = context.process(key, safemapping)
         except TemplateNotFound:
-            v = ''
+            v = default
     if callable(v):
         return v(**mapping)
     return v