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