[PATCH] templates: let extensions add own template maps

liscju piotr.listkiewicz at gmail.com
Fri Sep 9 02:41:45 EDT 2016


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1473403080 -7200
#      Fri Sep 09 08:38:00 2016 +0200
# Node ID 972114f70fb6f57265299aa16d590f79d8ed1a1a
# Parent  b42c26b0a78550d1b238674b5ffad6123ec9b76c
templates: let extensions add own template maps

Before this patch template maps were checked only in templates
directory in mercurial sources. This commit add possibility for
extension to add own template paths by exttemplatepaths list.

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -24,6 +24,8 @@ from . import (
     util,
 )
 
+exttemplatepaths = []
+
 # template parsing
 
 elements = {
@@ -1149,6 +1151,7 @@ def templatepaths():
     pathsrel = ['templates']
     paths = [os.path.normpath(os.path.join(util.datapath, f))
              for f in pathsrel]
+    paths.extend(exttemplatepaths)
     return [p for p in paths if os.path.isdir(p)]
 
 def templatepath(name):
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -1520,3 +1520,37 @@ Test synopsis and docstring extending
   hg bookmarks [OPTIONS]... [NAME]... GREPME [--foo] [-x]
       GREPME make sure that this is in the help!
 
+  $ cd ..
+  $ mkdir templates
+  $ cd templates
+  $ cat > map-cmdline.exttempl <<EOF
+  > %include map-cmdline.default
+  > changeset = 'Additional ext info\n{cset}{branches}\n'
+  > EOF
+  $ cd ..
+  $ cat > exttempl.py <<EOF
+  > import os
+  > from mercurial import templater
+  > def uisetup(ui):
+  >     templater.exttemplatepaths.append(
+  >         os.path.abspath(os.path.join(os.path.dirname(__file__),
+  >                                      'templates')))
+  > EOF
+  $ abspath=`pwd`/exttempl.py
+  $ echo '[extensions]' >> $HGRCPATH
+  $ echo "exthelp = $abspath" >> $HGRCPATH
+  $ hg init exttemplrepo
+  $ cd exttemplrepo
+  $ echo "a" >> a
+  $ hg add a
+  $ hg commit -m "a"
+  $ echo "b" >> b
+  $ hg add b
+  $ hg commit -m "b"
+  $ hg log -T exttempl
+  Additional ext info
+  changeset:   1:d2ae7f538514
+  
+  Additional ext info
+  changeset:   0:cb9a9f314b8b
+  


More information about the Mercurial-devel mailing list