Show More
@@ -1,25 +1,40 b'' | |||||
1 | from mercurial import util |
|
1 | from mercurial import util | |
2 |
|
2 | |||
3 | class namespaces(object): |
|
3 | class namespaces(object): | |
4 | """ |
|
4 | """ | |
5 | provides an interface to register a generic many-to-many mapping between |
|
5 | provides an interface to register a generic many-to-many mapping between | |
6 | some (namespaced) names and nodes. The goal here is to control the |
|
6 | some (namespaced) names and nodes. The goal here is to control the | |
7 | pollution of jamming things into tags or bookmarks (in extension-land) and |
|
7 | pollution of jamming things into tags or bookmarks (in extension-land) and | |
8 | to simplify internal bits of mercurial: log output, tab completion, etc. |
|
8 | to simplify internal bits of mercurial: log output, tab completion, etc. | |
9 |
|
9 | |||
10 | More precisely, we define a list of names (the namespace) and a mapping of |
|
10 | More precisely, we define a list of names (the namespace) and a mapping of | |
11 | names to nodes. This name mapping returns a list of nodes. |
|
11 | names to nodes. This name mapping returns a list of nodes. | |
12 |
|
12 | |||
13 | Furthermore, each name mapping will be passed a name to lookup which might |
|
13 | Furthermore, each name mapping will be passed a name to lookup which might | |
14 | not be in its domain. In this case, each method should return an empty list |
|
14 | not be in its domain. In this case, each method should return an empty list | |
15 | and not raise an error. |
|
15 | and not raise an error. | |
16 |
|
16 | |||
17 | We'll have a dictionary '_names' where each key is a namespace and |
|
17 | We'll have a dictionary '_names' where each key is a namespace and | |
18 | its value is a dictionary of functions: |
|
18 | its value is a dictionary of functions: | |
19 | 'namemap': function that takes a name and returns a list of nodes |
|
19 | 'namemap': function that takes a name and returns a list of nodes | |
20 | """ |
|
20 | """ | |
21 |
|
21 | |||
22 | _names_version = 0 |
|
22 | _names_version = 0 | |
23 |
|
23 | |||
24 | def __init__(self): |
|
24 | def __init__(self): | |
25 | self._names = util.sortdict() |
|
25 | self._names = util.sortdict() | |
|
26 | ||||
|
27 | def addnamespace(self, namespace, namemap, order=None): | |||
|
28 | """ | |||
|
29 | register a namespace | |||
|
30 | ||||
|
31 | namespace: the name to be registered (in plural form) | |||
|
32 | namemap: function that inputs a node, output name(s) | |||
|
33 | order: optional argument to specify the order of namespaces | |||
|
34 | (e.g. 'branches' should be listed before 'bookmarks') | |||
|
35 | """ | |||
|
36 | val = {'namemap': namemap} | |||
|
37 | if order is not None: | |||
|
38 | self._names.insert(order, namespace, val) | |||
|
39 | else: | |||
|
40 | self._names[namespace] = val |
General Comments 0
You need to be logged in to leave comments.
Login now