[PATCH 1 of 6] templater: simplify merge of __base__ dicts by reading it first

Yuya Nishihara yuya at tcha.org
Sat Oct 14 10:41:10 UTC 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1471685582 -32400
#      Sat Aug 20 18:33:02 2016 +0900
# Node ID 4725df3708cfa2117b12c9e1ee0d1a6143d7e87d
# Parent  4c322b95a6ab7edf81ec6a7971c2746340da27b0
templater: simplify merge of __base__ dicts by reading it first

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -1344,6 +1344,26 @@ def _readmapfile(mapfile):
 
     cache = {}
     tmap = {}
+
+    val = conf.get('', '__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))
+
+        # fallback check in template paths
+        if not os.path.exists(path):
+            for p in templatepaths():
+                p2 = util.normpath(os.path.join(p, val))
+                if os.path.isfile(p2):
+                    path = p2
+                    break
+                p3 = util.normpath(os.path.join(p2, "map"))
+                if os.path.isfile(p3):
+                    path = p3
+                    break
+
+        cache, tmap = _readmapfile(path)
+
     for key, val in conf[''].items():
         if not val:
             raise error.ParseError(_('missing value'), conf.source('', key))
@@ -1352,30 +1372,7 @@ def _readmapfile(mapfile):
                 raise error.ParseError(_('unmatched quotes'),
                                        conf.source('', key))
             cache[key] = unquotestring(val)
-        elif key == "__base__":
-            # treat as a pointer to a base class for this style
-            path = util.normpath(os.path.join(base, val))
-
-            # fallback check in template paths
-            if not os.path.exists(path):
-                for p in templatepaths():
-                    p2 = util.normpath(os.path.join(p, val))
-                    if os.path.isfile(p2):
-                        path = p2
-                        break
-                    p3 = util.normpath(os.path.join(p2, "map"))
-                    if os.path.isfile(p3):
-                        path = p3
-                        break
-
-            bcache, btmap = _readmapfile(path)
-            for k in bcache:
-                if k not in cache:
-                    cache[k] = bcache[k]
-            for k in btmap:
-                if k not in tmap:
-                    tmap[k] = btmap[k]
-        else:
+        elif key != '__base__':
             val = 'default', val
             if ':' in val[1]:
                 val = val[1].split(':', 1)


More information about the Mercurial-devel mailing list