Patchwork [2,of,4,V2] templater: process mapping dict by resource callables

login
register
mail settings
Submitter Yuya Nishihara
Date March 16, 2018, 4:03 p.m.
Message ID <5d94efb75658163ab7db.1521216199@mimosa>
Download mbox | patch
Permalink /patch/29567/
State New
Headers show

Comments

Yuya Nishihara - March 16, 2018, 4:03 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1520770322 -32400
#      Sun Mar 11 21:12:02 2018 +0900
# Node ID 5d94efb75658163ab7db01acbefeb6469bc97739
# Parent  5def08d8870b1a9b4f0d88a80ac8f4696a199ea6
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.

Patch

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.