Patchwork [6,of,7,V2] namespaces: generate template keyword when registering a namespace

mail settings
Submitter Sean Farley
Date Dec. 18, 2014, 9:10 p.m.
Message ID <61be8fb2ece5b5a7f0ca.1418937050@laptop.local>
Download mbox | patch
Permalink /patch/7178/
State Accepted
Headers show


Sean Farley - Dec. 18, 2014, 9:10 p.m.
# HG changeset patch
# User Sean Farley <>
# Date 1413526749 25200
#      Thu Oct 16 23:19:09 2014 -0700
# Node ID 61be8fb2ece5b5a7f0ca6b5ecaa4c274c7e0190e
# Parent  077665448c9df324d59f06d905dd743bc7ae01e3
namespaces: generate template keyword when registering a namespace

For any namespace, we generate a template keyword. For example, given a
namespace 'babar', we automatically have the ability to use it in a template:

hg log -r . -T '{babars % "King: {babar}\n"}'

Furthermore, we only generate this keyword for a namespace if one doesn't
already exist. This is necessary for 'branches' and 'bookmarks' since both of
those have concepts of 'current' (something outside the namespace api) and also
allows extensions to override default behavior if desired.


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -1,7 +1,8 @@ 
 from i18n import _
 from mercurial import util
+import templatekw
 def tolist(val):
     a convenience method to return an empty list instead of None
@@ -72,10 +73,17 @@  class namespaces(object):
         if order is not None:
             self._names.insert(order, namespace, val)
             self._names[namespace] = val
+        # we only generate a template keyword if one does not already exist
+        if namespace not in templatekw.keywords:
+            def generatekw(**args):
+                return templatekw.shownames(namespace, **args)
+            templatekw.keywords[namespace] = generatekw
     def singlenode(self, repo, name):
         Return the 'best' node for the given name. Best means the first node
         in the first nonempty list returned by a name-to-nodes mapping function
         in the defined precedence order.