Patchwork [3,of,6,json-style] templater: allow styles to specify a default engine

login
register
mail settings
Submitter Gregory Szorc
Date Dec. 31, 2014, 10:45 p.m.
Message ID <055802e347f62d475602.1420065933@gps-mbp.local>
Download mbox | patch
Permalink /patch/7288/
State Changes Requested
Headers show

Comments

Gregory Szorc - Dec. 31, 2014, 10:45 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1420052574 28800
#      Wed Dec 31 11:02:54 2014 -0800
# Node ID 055802e347f62d47560201096e6f280601b2f60d
# Parent  94f5d1af421d623685e7c88da54872a2dedef21f
templater: allow styles to specify a default engine

Currently, templater resolves the template engine separately for each
named entry. This means that if a new named template is added, a new
entry must be added to the mapfile.

Some styles may wish to be used with a custom "catch-all" engine that
isn't the default. (A use case will be presented in subsequent patches.)
This patch enables the presence of a special "defaultengine" entry in
the mapfile to override the default selection of the "default" engine
for all templates.

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -659,8 +659,9 @@  class templater(object):
         self.filters.update(filters)
         self.defaults = defaults
         self.minchunk, self.maxchunk = minchunk, maxchunk
         self.ecache = {}
+        self.defaultengine = 'default'
 
         if not mapfile:
             return
         if not os.path.exists(mapfile):
@@ -678,8 +679,10 @@  class templater(object):
                     self.cache[key] = parsestring(val)
                 except SyntaxError, inst:
                     raise SyntaxError('%s: %s' %
                                       (conf.source('', key), inst.args[0]))
+            elif key == 'defaultengine':
+                self.defaultengine = val
             else:
                 val = 'default', val
                 if ':' in val[1]:
                     val = val[1].split(':', 1)
@@ -701,9 +704,9 @@  class templater(object):
                               (self.map[t][1], inst.args[1]))
         return self.cache[t]
 
     def __call__(self, t, **mapping):
-        ttype = t in self.map and self.map[t][0] or 'default'
+        ttype = t in self.map and self.map[t][0] or self.defaultengine
         if ttype not in self.ecache:
             self.ecache[ttype] = engines[ttype](self.load,
                                                  self.filters, self.defaults)
         proc = self.ecache[ttype]