Patchwork [1,of,5] templater: move function table to the "context" object

login
register
mail settings
Submitter Yuya Nishihara
Date March 9, 2018, 12:45 p.m.
Message ID <31bdcdeece08af24761f.1520599530@mimosa>
Download mbox | patch
Permalink /patch/29169/
State Accepted
Headers show

Comments

Yuya Nishihara - March 9, 2018, 12:45 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1520515236 -32400
#      Thu Mar 08 22:20:36 2018 +0900
# Node ID 31bdcdeece08af24761fd359f48766c7274cf71a
# Parent  168badbb03b574d2a77ae503d3b77709c68e0537
templater: move function table to the "context" object

Prepares for splitting template functions from templater.py.

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -493,8 +493,8 @@  def buildfilter(exp, context):
         filt = context._filters[n]
         arg = compileexp(exp[1], context, methods)
         return (runfilter, (arg, filt))
-    if n in funcs:
-        f = funcs[n]
+    if n in context._funcs:
+        f = context._funcs[n]
         args = _buildfuncargs(exp[1], context, methods, n, f._argspec)
         return (f, args)
     raise error.ParseError(_("unknown function '%s'") % n)
@@ -595,8 +595,8 @@  def runarithmetic(context, mapping, data
 
 def buildfunc(exp, context):
     n = getsymbol(exp[1])
-    if n in funcs:
-        f = funcs[n]
+    if n in context._funcs:
+        f = context._funcs[n]
         args = _buildfuncargs(exp[2], context, exprmethods, n, f._argspec)
         return (f, args)
     if n in context._filters:
@@ -1376,6 +1376,7 @@  class engine(object):
         if filters is None:
             filters = {}
         self._filters = filters
+        self._funcs = funcs  # make this a parameter if needed
         if defaults is None:
             defaults = {}
         if resources is None: