changeset 23554:75f9643cab1b

namespaces: add a method to register new namespaces
author Sean Farley <sean.michael.farley@gmail.com>
date Fri, 17 Oct 2014 11:25:51 -0700
parents 7cebb6a8c75f
children f08f6a7d4d5f
files mercurial/namespaces.py
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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