[PATCH 2 of 5] templater: process mapping dict by resource callables

Yuya Nishihara yuya at tcha.org
Wed Mar 14 10:27:35 EDT 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1520770322 -32400
#      Sun Mar 11 21:12:02 2018 +0900
# Node ID aa30f31078218be74a17c0f6ea923a94c9e9f738
# Parent  2861824d0172677fbb677c5f861d69786860457e
templater: process mapping dict by resource callables

Now a resource item is a callable, so let's make it look up a resource object
by itself.

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -508,6 +508,9 @@ def templateresources(ui, repo=None):
     }
 
     def getsome(context, mapping, key):
+        v = mapping.get(key)
+        if v is not None:
+            return v
         return resmap.get(key)
 
     return {
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -565,8 +565,6 @@ class engine(object):
         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 @@ class templater(object):
         - ``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.
 


More information about the Mercurial-devel mailing list