namespaces: add template name of a namespace
authorSean Farley <sean.michael.farley@gmail.com>
Mon, 15 Dec 2014 00:09:52 -0800
changeset 23605 4c4c967814ef
parent 23604 bb304f9b05d0
child 23606 80e3cbe227d1
namespaces: add template name of a namespace The template name property will be used in upcoming patches to automatically generate a template keyword. For example, given a namespace called 'babars', we will automatically generate a template keyword 'babar' such that we can use it in the following way, $ hg log -r . -T '{babars % "King: {babar}\n"}'
mercurial/namespaces.py
--- a/mercurial/namespaces.py	Fri Dec 19 00:11:56 2014 +0900
+++ b/mercurial/namespaces.py	Mon Dec 15 00:09:52 2014 -0800
@@ -26,6 +26,8 @@
 
     We'll have a dictionary '_names' where each key is a namespace and
     its value is a dictionary of functions:
+      'templatename': name to use for templating (usually the singular form
+                      of the plural namespace name)
       'namemap': function that takes a name and returns a list of nodes
     """
 
@@ -38,25 +40,27 @@
 
         # we need current mercurial named objects (bookmarks, tags, and
         # branches) to be initialized somewhere, so that place is here
-        addns("bookmarks",
+        addns("bookmarks", "bookmark",
               lambda repo, name: tolist(repo._bookmarks.get(name)))
 
-        addns("tags",
+        addns("tags", "tag",
               lambda repo, name: tolist(repo._tagscache.tags.get(name)))
 
-        addns("branches",
+        addns("branches", "branch",
               lambda repo, name: tolist(repo.branchtip(name)))
 
-    def addnamespace(self, namespace, namemap, order=None):
+    def addnamespace(self, namespace, templatename, namemap, order=None):
         """
         register a namespace
 
         namespace: the name to be registered (in plural form)
+        templatename: the name to use for templating
         namemap: function that inputs a node, output name(s)
         order: optional argument to specify the order of namespaces
                (e.g. 'branches' should be listed before 'bookmarks')
         """
-        val = {'namemap': namemap}
+        val = {'templatename': templatename,
+               'namemap': namemap}
         if order is not None:
             self._names.insert(order, namespace, val)
         else: