diff mercurial/templater.py @ 34714:f4aeb952ab77

templater: load template fragments from [templates] section in map file This allows us to %include map-cmdline.<style> file in our .hgrc files. The syntax is slightly different as hgrc doesn't support loading an external template file, but map-cmdline files don't use this feature, so the syntax can be considered identical in practice. Unnamed section is remapped for backward compatibility.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 14 Oct 2017 17:51:01 +0900
parents 56f085334611
children f17a0e18c47e
line wrap: on
line diff
--- a/mercurial/templater.py	Sat Oct 14 17:41:41 2017 +0900
+++ b/mercurial/templater.py	Sat Oct 14 17:51:01 2017 +0900
@@ -1340,12 +1340,12 @@
 
     base = os.path.dirname(mapfile)
     conf = config.config(includepaths=templatepaths())
-    conf.read(mapfile)
+    conf.read(mapfile, remap={'': 'templates'})
 
     cache = {}
     tmap = {}
 
-    val = conf.get('', '__base__')
+    val = conf.get('templates', '__base__')
     if val and val[0] not in "'\"":
         # treat as a pointer to a base class for this style
         path = util.normpath(os.path.join(base, val))
@@ -1364,13 +1364,14 @@
 
         cache, tmap = _readmapfile(path)
 
-    for key, val in conf[''].items():
+    for key, val in conf['templates'].items():
         if not val:
-            raise error.ParseError(_('missing value'), conf.source('', key))
+            raise error.ParseError(_('missing value'),
+                                   conf.source('templates', key))
         if val[0] in "'\"":
             if val[0] != val[-1]:
                 raise error.ParseError(_('unmatched quotes'),
-                                       conf.source('', key))
+                                       conf.source('templates', key))
             cache[key] = unquotestring(val)
         elif key != '__base__':
             val = 'default', val