[PATCH] templater: add template path to __base__ search

Matt Mackall mpm at selenic.com
Thu Aug 25 00:48:28 UTC 2016


# HG changeset patch
# User Matt Mackall <mpm at selenic.com>
# Date 1472085825 25200
#      Wed Aug 24 17:43:45 2016 -0700
# Node ID 1ec871261bb777e24f21cb180fce199cb49c55ea
# Parent  5f86818c95e5ea59c48dfceca2e286cd11f9a800
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".

diff -r 5f86818c95e5 -r 1ec871261bb7 mercurial/templater.py
--- a/mercurial/templater.py	Wed Aug 17 13:43:13 2016 -0500
+++ b/mercurial/templater.py	Wed Aug 24 17:43:45 2016 -0700
@@ -1029,6 +1029,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:
diff -r 5f86818c95e5 -r 1ec871261bb7 tests/test-command-template.t
--- a/tests/test-command-template.t	Wed Aug 17 13:43:13 2016 -0500
+++ 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'


More information about the Mercurial-devel mailing list