[PATCH v2] templates: limit -Tlist to supported templates

timeless timeless at mozdev.org
Tue Dec 15 16:51:12 UTC 2015


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1450065308 0
#      Mon Dec 14 03:55:08 2015 +0000
# Node ID df108fa16c4f680cd402f983d5f0a1830f00c629
# Parent  944af8e2eb4cddf96ba5b8a96854528b40979715
templates: limit -Tlist to supported templates

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -178,7 +178,7 @@
         return tmpl, None
 
     if tmpl == 'list':
-        ui.write(_("available styles: %s\n") % templater.stylelist())
+        ui.write(_("available styles: %s\n") % templater.stylelist(topic))
         raise error.Abort(_("specify a template"))
 
     # perhaps it's a path to a map or a template
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -828,16 +828,20 @@
 
 engines = {'default': engine}
 
-def stylelist():
+def stylelist(topic=None):
     paths = templatepaths()
     if not paths:
         return _('no templates found, try `hg debuginstall` for more info')
     dirlist =  os.listdir(paths[0])
     stylelist = []
     for file in dirlist:
+        # FIXME if file is actually a directory, this will break
+        # resulting in an exception instead of a list.
         split = file.split(".")
         if split[0] == "map-cmdline":
-            stylelist.append(split[1])
+            t = templater(templatepath(file), liststyles=False)
+            if topic is None or topic in t:
+                stylelist.append(split[1])
     return ", ".join(sorted(stylelist))
 
 class TemplateNotFound(error.Abort):
@@ -846,7 +850,7 @@
 class templater(object):
 
     def __init__(self, mapfile, filters=None, defaults=None, cache=None,
-                 minchunk=1024, maxchunk=65536):
+                 minchunk=1024, maxchunk=65536, liststyles=True):
         '''set up template engine.
         mapfile is name of file to read map definitions from.
         filters is dict of functions. each transforms a value into another.
@@ -873,8 +877,11 @@
         if not mapfile:
             return
         if not os.path.exists(mapfile):
+            hint = None
+            if liststyles:
+                hint=_("available styles: %s") % stylelist()
             raise error.Abort(_("style '%s' not found") % mapfile,
-                             hint=_("available styles: %s") % stylelist())
+                             hint=hint)
 
         conf = config.config(includepaths=templatepaths())
         conf.read(mapfile)
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -997,6 +997,13 @@
   abort: specify a template
   [255]
 
+Only supported styles (this test will change with time):
+
+  $ hg manifest -T list
+  available styles: bisect, default, phases, status
+  abort: specify a template
+  [255]
+
 Error if style missing key:
 
   $ echo 'q = q' > t


More information about the Mercurial-devel mailing list