[PATCH 2 of 8] namespaces: add a method to register new namespaces
Sean Farley
sean.michael.farley at gmail.com
Sun Dec 14 18:37:50 CST 2014
# HG changeset patch
# User Sean Farley <sean.michael.farley at 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')
+
+ """
+ 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
More information about the Mercurial-devel
mailing list