Patchwork [3,of,3] templater: remove redundant member variables from templater class

login
register
mail settings
Submitter Yuya Nishihara
Date June 22, 2018, 12:49 p.m.
Message ID <09315831bf33b64a7898.1529671757@mimosa>
Download mbox | patch
Permalink /patch/32379/
State Accepted
Headers show

Comments

Yuya Nishihara - June 22, 2018, 12:49 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1529588022 -32400
#      Thu Jun 21 22:33:42 2018 +0900
# Node ID 09315831bf33b64a78987f1c75a89093b7bfb695
# Parent  9a00b95221eb92f0df923315911e61641a4e0054
templater: remove redundant member variables from templater class

We no longer need them since the engine is instantiated in __init__().

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -863,17 +863,11 @@  class templater(object):
         self.cache may be updated later to register additional template
         fragments.
         """
-        if filters is None:
-            filters = {}
-        if defaults is None:
-            defaults = {}
-        self._filters = templatefilters.filters.copy()
-        self._filters.update(filters)
-        self.defaults = defaults
-        self._resources = resources
+        allfilters = templatefilters.filters.copy()
+        if filters:
+            allfilters.update(filters)
         self._loader = loader(cache, aliases)
-        self._proc = engine(self._loader.load, self._filters, self.defaults,
-                            self._resources)
+        self._proc = engine(self._loader.load, allfilters, defaults, resources)
         self._minchunk, self._maxchunk = minchunk, maxchunk
 
     @classmethod
@@ -894,6 +888,15 @@  class templater(object):
     def cache(self):
         return self._loader.cache
 
+    # for highlight extension to insert one-time 'colorize' filter
+    @property
+    def _filters(self):
+        return self._proc._filters
+
+    @property
+    def defaults(self):
+        return self._proc._defaults
+
     def load(self, t):
         """Get parsed tree for the given template name. Use a local cache."""
         return self._loader.load(t)