[PATCH 5 of 7 V2] templatekw: add helper method to generate a template keyword for a namespace

Sean Farley sean.michael.farley at gmail.com
Thu Dec 18 15:10:49 CST 2014


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1418613337 28800
#      Sun Dec 14 19:15:37 2014 -0800
# Node ID 077665448c9df324d59f06d905dd743bc7ae01e3
# Parent  a6308360a56c275faf1fe8807babd48a37c0d012
templatekw: add helper method to generate a template keyword for a namespace

This marks our second feature of the namespace api: automatic template keyword.
This patch adds a method that takes in a namespace and uses the node-to-name
map to output the list of names.

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -376,10 +376,18 @@ def showsubrepos(**args):
 
 def showtags(**args):
     """:tags: List of strings. Any tags associated with the changeset."""
     return showlist('tag', args['ctx'].tags(), **args)
 
+def shownames(namespace, **args):
+    """helper method to generate a template keyword for a namespace"""
+    ctx = args['ctx']
+    repo = ctx._repo
+    names = repo.names.names(repo, namespace, ctx.node())
+    return showlist(repo.names.templatename(namespace), names,
+                    plural=namespace, **args)
+
 # keywords are callables like:
 # fn(repo, ctx, templ, cache, revcache, **args)
 # with:
 # repo - current repository instance
 # ctx - the changectx being displayed


More information about the Mercurial-devel mailing list