##// END OF EJS Templates
namespaces: add nodemap property...
Sean Farley -
r23607:0fd778ef default
parent child Browse files
Show More
@@ -17,8 +17,9 b' class namespaces(object):'
17 pollution of jamming things into tags or bookmarks (in extension-land) and
17 pollution of jamming things into tags or bookmarks (in extension-land) and
18 to simplify internal bits of mercurial: log output, tab completion, etc.
18 to simplify internal bits of mercurial: log output, tab completion, etc.
19
19
20 More precisely, we define a list of names (the namespace) and a mapping of
20 More precisely, we define a list of names (the namespace), a mapping of
21 names to nodes. This name mapping returns a list of nodes.
21 names to nodes, and a mapping from nodes to names. Each mapping
22 returns a list of nodes.
22
23
23 Furthermore, each name mapping will be passed a name to lookup which might
24 Furthermore, each name mapping will be passed a name to lookup which might
24 not be in its domain. In this case, each method should return an empty list
25 not be in its domain. In this case, each method should return an empty list
@@ -29,6 +30,7 b' class namespaces(object):'
29 'templatename': name to use for templating (usually the singular form
30 'templatename': name to use for templating (usually the singular form
30 of the plural namespace name)
31 of the plural namespace name)
31 'namemap': function that takes a name and returns a list of nodes
32 'namemap': function that takes a name and returns a list of nodes
33 'nodemap': function that takes a node and returns a list of names
32 """
34 """
33
35
34 _names_version = 0
36 _names_version = 0
@@ -41,26 +43,32 b' class namespaces(object):'
41 # we need current mercurial named objects (bookmarks, tags, and
43 # we need current mercurial named objects (bookmarks, tags, and
42 # branches) to be initialized somewhere, so that place is here
44 # branches) to be initialized somewhere, so that place is here
43 addns("bookmarks", "bookmark",
45 addns("bookmarks", "bookmark",
44 lambda repo, name: tolist(repo._bookmarks.get(name)))
46 lambda repo, name: tolist(repo._bookmarks.get(name)),
47 lambda repo, name: repo.nodebookmarks(name))
45
48
46 addns("tags", "tag",
49 addns("tags", "tag",
47 lambda repo, name: tolist(repo._tagscache.tags.get(name)))
50 lambda repo, name: tolist(repo._tagscache.tags.get(name)),
51 lambda repo, name: repo.nodetags(name))
48
52
49 addns("branches", "branch",
53 addns("branches", "branch",
50 lambda repo, name: tolist(repo.branchtip(name)))
54 lambda repo, name: tolist(repo.branchtip(name)),
55 lambda repo, node: [repo[node].branch()])
51
56
52 def addnamespace(self, namespace, templatename, namemap, order=None):
57 def addnamespace(self, namespace, templatename, namemap, nodemap,
58 order=None):
53 """
59 """
54 register a namespace
60 register a namespace
55
61
56 namespace: the name to be registered (in plural form)
62 namespace: the name to be registered (in plural form)
57 templatename: the name to use for templating
63 templatename: the name to use for templating
58 namemap: function that inputs a node, output name(s)
64 namemap: function that inputs a node, output name(s)
65 nodemap: function that inputs a name, output node(s)
59 order: optional argument to specify the order of namespaces
66 order: optional argument to specify the order of namespaces
60 (e.g. 'branches' should be listed before 'bookmarks')
67 (e.g. 'branches' should be listed before 'bookmarks')
61 """
68 """
62 val = {'templatename': templatename,
69 val = {'templatename': templatename,
63 'namemap': namemap}
70 'namemap': namemap,
71 'nodemap': nodemap}
64 if order is not None:
72 if order is not None:
65 self._names.insert(order, namespace, val)
73 self._names.insert(order, namespace, val)
66 else:
74 else:
General Comments 0
You need to be logged in to leave comments. Login now