##// END OF EJS Templates
namespaces: update documentation and code indentation...
Sean Farley -
r23718:42908c32 default
parent child Browse files
Show More
@@ -12,26 +12,9 b' def tolist(val):'
12 12 return [val]
13 13
14 14 class namespaces(object):
15 """
16 provides an interface to register a generic many-to-many mapping between
17 some (namespaced) names and nodes. The goal here is to control the
18 pollution of jamming things into tags or bookmarks (in extension-land) and
19 to simplify internal bits of mercurial: log output, tab completion, etc.
20
21 More precisely, we define a list of names (the namespace), a mapping of
22 names to nodes, and a mapping from nodes to names. Each mapping
23 returns a list of nodes.
15 """provides an interface to register and operate on multiple namespaces. See
16 the namespace class below for details on the namespace object.
24 17
25 Furthermore, each name mapping will be passed a name to lookup which might
26 not be in its domain. In this case, each method should return an empty list
27 and not raise an error.
28
29 We'll have a dictionary '_names' where each key is a namespace and
30 its value is a dictionary of functions:
31 'templatename': name to use for templating (usually the singular form
32 of the plural namespace name)
33 'namemap': function that takes a name and returns a list of nodes
34 'nodemap': function that takes a node and returns a list of names
35 18 """
36 19
37 20 _names_version = 0
@@ -45,30 +28,27 b' class namespaces(object):'
45 28 # we need current mercurial named objects (bookmarks, tags, and
46 29 # branches) to be initialized somewhere, so that place is here
47 30 n = ns("bookmarks", "bookmark",
48 lambda repo, name: tolist(repo._bookmarks.get(name)),
49 lambda repo, name: repo.nodebookmarks(name))
31 lambda repo, name: tolist(repo._bookmarks.get(name)),
32 lambda repo, name: repo.nodebookmarks(name))
50 33 self.addnamespace(n)
51 34
52 35 n = ns("tags", "tag",
53 lambda repo, name: tolist(repo._tagscache.tags.get(name)),
54 lambda repo, name: repo.nodetags(name))
36 lambda repo, name: tolist(repo._tagscache.tags.get(name)),
37 lambda repo, name: repo.nodetags(name))
55 38 self.addnamespace(n)
56 39
57 40 n = ns("branches", "branch",
58 lambda repo, name: tolist(repo.branchtip(name)),
59 lambda repo, node: [repo[node].branch()])
41 lambda repo, name: tolist(repo.branchtip(name)),
42 lambda repo, node: [repo[node].branch()])
60 43 self.addnamespace(n)
61 44
62 45 def addnamespace(self, namespace, order=None):
63 """
64 register a namespace
46 """register a namespace
65 47
66 48 namespace: the name to be registered (in plural form)
67 templatename: the name to use for templating
68 namemap: function that inputs a node, output name(s)
69 nodemap: function that inputs a name, output node(s)
70 49 order: optional argument to specify the order of namespaces
71 50 (e.g. 'branches' should be listed before 'bookmarks')
51
72 52 """
73 53 if order is not None:
74 54 self._names.insert(order, namespace.name, namespace)
General Comments 0
You need to be logged in to leave comments. Login now