[PATCH 1 of 9] templater: add context.preload(t) to test if the specified template exists

Yuya Nishihara yuya at tcha.org
Wed Mar 21 13:51:49 UTC 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1521207400 -32400
#      Fri Mar 16 22:36:40 2018 +0900
# Node ID 5f2336d71c2403543586388e4ee628e221138870
# Parent  e2a0aaec7d86771220d5290549e86d634a7f5178
templater: add context.preload(t) to test if the specified template exists

I'm going to remove 'templ' from the resources dict because it is the only
resource that the caller can't provide. This also implies that putting
'templ' into the resources dict creates a reference cycle.

context.preload(t) will be used in place of templater.__contains__().

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -627,6 +627,14 @@ class engine(object):
                 raise
         return self._cache[t]
 
+    def preload(self, t):
+        """Load, parse, and cache the specified template if available"""
+        try:
+            self._load(t)
+            return True
+        except templateutil.TemplateNotFound:
+            return False
+
     def process(self, t, mapping):
         '''Perform expansion. t is name of map element to expand.
         mapping contains added elements for use during expansion. Is a


More information about the Mercurial-devel mailing list