namespaces: add a method to register new namespaces
authorSean Farley <sean.michael.farley@gmail.com>
Fri, 17 Oct 2014 11:25:51 -0700
changeset 23554 75f9643cab1b
parent 23553 7cebb6a8c75f
child 23555 f08f6a7d4d5f
namespaces: add a method to register new namespaces
mercurial/namespaces.py
--- a/mercurial/namespaces.py	Sun Dec 14 12:29:28 2014 -0800
+++ b/mercurial/namespaces.py	Fri Oct 17 11:25:51 2014 -0700
@@ -23,3 +23,18 @@
 
     def __init__(self):
         self._names = util.sortdict()
+
+    def addnamespace(self, namespace, namemap, order=None):
+        """
+        register a namespace
+
+        namespace: the name to be registered (in plural form)
+        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}
+        if order is not None:
+            self._names.insert(order, namespace, val)
+        else:
+            self._names[namespace] = val