changeset 23610:9266d1dd6a6e

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.
author Sean Farley <sean.michael.farley@gmail.com>
date Thu, 16 Oct 2014 23:19:09 -0700
parents 40fcf6c05217
children d69a7fc68ad5
files mercurial/namespaces.py
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/namespaces.py	Sun Dec 14 19:15:37 2014 -0800
+++ b/mercurial/namespaces.py	Thu Oct 16 23:19:09 2014 -0700
@@ -1,5 +1,6 @@
 from i18n import _
 from mercurial import util
+import templatekw
 
 def tolist(val):
     """
@@ -74,6 +75,13 @@
         else:
             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