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

login
register
mail settings
Submitter Sean Farley
Date Dec. 18, 2014, 9:10 p.m.
Message ID <077665448c9df324d59f.1418937049@laptop.local>
Download mbox | patch
Permalink /patch/7177/
State Accepted
Headers show

Comments

Sean Farley - Dec. 18, 2014, 9:10 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@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.

Patch

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