templater: process mapping dict by resource callables
authorYuya Nishihara <yuya@tcha.org>
Sun, 11 Mar 2018 21:12:02 +0900
changeset 36983 036e4483d3a1
parent 36982 255f635c3204
child 36984 939e0983c1d9
templater: process mapping dict by resource callables A resource item is a callable, so let's make it look up a resource object by itself.
mercurial/formatter.py
mercurial/templater.py
--- a/mercurial/formatter.py	Sun Mar 11 21:05:29 2018 +0900
+++ b/mercurial/formatter.py	Sun Mar 11 21:12:02 2018 +0900
@@ -508,6 +508,9 @@
     }
 
     def getsome(context, mapping, key):
+        v = mapping.get(key)
+        if v is not None:
+            return v
         return resmap.get(key)
 
     return {
--- a/mercurial/templater.py	Sun Mar 11 21:05:29 2018 +0900
+++ b/mercurial/templater.py	Sun Mar 11 21:12:02 2018 +0900
@@ -565,8 +565,6 @@
         evaluation"""
         v = None
         if key in self._resources:
-            v = mapping.get(key)
-        if v is None and key in self._resources:
             v = self._resources[key](self, mapping, key)
         if v is None:
             raise templateutil.ResourceUnavailable(
@@ -671,8 +669,7 @@
         - ``defaults``: a dict of symbol values/functions; may be overridden
           by a ``mapping`` dict.
         - ``resources``: a dict of functions returning internal data
-          (e.g. cache), inaccessible from user template; may be overridden by
-          a ``mapping`` dict.
+          (e.g. cache), inaccessible from user template.
         - ``cache``: a dict of preloaded template fragments.
         - ``aliases``: a list of alias (name, replacement) pairs.