Patchwork [2,of,8] namespaces: add a method to register new namespaces

login
register
mail settings
Submitter Sean Farley
Date Dec. 15, 2014, 12:37 a.m.
Message ID <98bc28635ee1999c778e.1418603870@laptop.local>
Download mbox | patch
Permalink /patch/7095/
State Accepted
Headers show

Comments

Sean Farley - Dec. 15, 2014, 12:37 a.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1413570351 25200
#      Fri Oct 17 11:25:51 2014 -0700
# Node ID 98bc28635ee1999c778e5c98f55423147d316a9e
# Parent  eb7489c4b2f83efcfbeca4c3b68022bd5596e352
namespaces: add a method to register new namespaces
Pierre-Yves David - Dec. 15, 2014, 1:06 a.m.
On 12/14/2014 04:37 PM, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1413570351 25200
> #      Fri Oct 17 11:25:51 2014 -0700
> # Node ID 98bc28635ee1999c778e5c98f55423147d316a9e
> # Parent  eb7489c4b2f83efcfbeca4c3b68022bd5596e352
> namespaces: add a method to register new namespaces
>
> diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py
> --- a/mercurial/namespaces.py
> +++ b/mercurial/namespaces.py
> @@ -32,5 +32,29 @@ class namespaces(object):
>
>       _names_version = 0
>
>       def __init__(self):
>           self._names = util.sortdict()
> +
> +    def addnamespace(self, namespace, singular, names, namemap, nodemap,
> +                     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.)
> +        names: function to list all names
> +        namemap: function that inputs a node, output name(s)
> +        nodemap: function that inputs a name, output node(s)
> +        order: optional argument to specify the order of namespaces
> +               (e.g. 'branches' should be listed before 'bookmarks')
> +
> +        """

We should probably drop all the extra stuff not used in the first 
series. (singular, nodemap) and reintroduce them when we actually adds 
the feature making use of them.

The surviving data are: namespace and namemap

Patch

diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py
--- a/mercurial/namespaces.py
+++ b/mercurial/namespaces.py
@@ -32,5 +32,29 @@  class namespaces(object):
 
     _names_version = 0
 
     def __init__(self):
         self._names = util.sortdict()
+
+    def addnamespace(self, namespace, singular, names, namemap, nodemap,
+                     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.)
+        names: function to list all names
+        namemap: function that inputs a node, output name(s)
+        nodemap: function that inputs a name, output node(s)
+        order: optional argument to specify the order of namespaces
+               (e.g. 'branches' should be listed before 'bookmarks')
+
+        """
+        val = {'singular': singular,
+               'names': names,
+               'namemap': namemap,
+               'nodemap': nodemap}
+        if order is not None:
+            self._names.insert(order, namespace, val)
+        else:
+            self._names[namespace] = val