From patchwork Wed Mar 21 13:51:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1, of, 9] templater: add context.preload(t) to test if the specified template exists From: Yuya Nishihara X-Patchwork-Id: 29687 Message-Id: <5f2336d71c2403543586.1521640309@mimosa> To: mercurial-devel@mercurial-scm.org Date: Wed, 21 Mar 2018 22:51:49 +0900 # HG changeset patch # User Yuya Nishihara # 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