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

login
register
mail settings
Submitter Yuya Nishihara
Date March 21, 2018, 1:51 p.m.
Message ID <5f2336d71c2403543586.1521640309@mimosa>
Download mbox | patch
Permalink /patch/29687/
State Accepted
Headers show

Comments

Yuya Nishihara - March 21, 2018, 1:51 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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__().

Patch

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