templater: add template path to __base__ search
authorMatt Mackall <mpm@selenic.com>
Wed, 24 Aug 2016 17:43:45 -0700
changeset 29848 b1f69dbdd76b
parent 29846 318e2b600b80
child 29849 f148bfa40489
templater: add template path to __base__ search This does a fall-back check for style files or directories that are in Mercurial's template path for user convenience. We intentionally don't use this for the built-in coal style because we don't want the style to mysteriously break if the working directory just happens to have a file named "paper".
mercurial/templater.py
tests/test-command-template.t
--- a/mercurial/templater.py	Tue Aug 23 16:40:08 2016 -0400
+++ b/mercurial/templater.py	Wed Aug 24 17:43:45 2016 -0700
@@ -1047,6 +1047,19 @@
         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:
--- a/tests/test-command-template.t	Tue Aug 23 16:40:08 2016 -0400
+++ b/tests/test-command-template.t	Wed Aug 24 17:43:45 2016 -0700
@@ -103,6 +103,18 @@
   $ hg log -l1 -T./map-simple
   8
 
+Test template map inheritance
+
+  $ echo "__base__ = map-cmdline.default" > map-simple
+  $ printf 'cset = "changeset: ***{rev}***\\n"\n' >> map-simple
+  $ hg log -l1 -T./map-simple
+  changeset: ***8***
+  tag:         tip
+  user:        test
+  date:        Wed Jan 01 10:01:00 2020 +0000
+  summary:     third
+  
+
 Template should precede style option
 
   $ hg log -l1 --style default -T '{rev}\n'