[PATCH 1 of 7] namespaces: add singular name of a namespace

Sean Farley sean.michael.farley at gmail.com
Wed Dec 17 00:01:55 UTC 2014


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1418630992 28800
#      Mon Dec 15 00:09:52 2014 -0800
# Node ID 47d0996687d81753386f01e26037be30992dbb59
# Parent  39cead85fd58ae6693592074656b284ed736d9bc
namespaces: add singular name of a namespace

Since there is no easy way to get the singular or plural form of a word in the
English language, we store both. This will be used later in the templating
machinery to automatically generate keywords.

diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py
--- a/mercurial/namespaces.py
+++ b/mercurial/namespaces.py
@@ -24,10 +24,12 @@ class namespaces(object):
     not be in its domain. In this case, each method should return an empty list
     and not raise an error.
 
     We'll have a dictionary '_names' where each key is a namespace and
     its value is a dictionary of functions:
+      'singular': singular name of the namespace (e.g. "bookmark"
+                  vs. "bookmarks")
       'namemap': function that takes a name and returns a list of nodes
     """
 
     _names_version = 0
 
@@ -36,29 +38,32 @@ class namespaces(object):
 
         addns = self.addnamespace
 
         # 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, singular, namemap, order=None):
         """
         register a namespace
 
         namespace: the name to be registered (in plural form)
+        singular: the singular naming of namespace (for output, e.g. log,
+                  templating, etc.)
         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 = {'singular': singular,
+               'namemap': namemap}
         if order is not None:
             self._names.insert(order, namespace, val)
         else:
             self._names[namespace] = val
 


More information about the Mercurial-devel mailing list