Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/namespaces.py @ 23718:42908c3275c6
namespaces: update documentation and code indentation
The previous patch changed just the functionality, while this patch focuses on
the documentation and indentation to keep review simple.
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Sun, 21 Dec 2014 13:06:24 -0800 |
parents | d8663e6153c1 |
children | d7324c242c3f |
comparison
equal
deleted
inserted
replaced
23717:d8663e6153c1 | 23718:42908c3275c6 |
---|---|
10 return [] | 10 return [] |
11 else: | 11 else: |
12 return [val] | 12 return [val] |
13 | 13 |
14 class namespaces(object): | 14 class namespaces(object): |
15 """ | 15 """provides an interface to register and operate on multiple namespaces. See |
16 provides an interface to register a generic many-to-many mapping between | 16 the namespace class below for details on the namespace object. |
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 | 17 |
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. | |
24 | |
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 _names_version = 0 | 20 _names_version = 0 |
38 | 21 |
39 def __init__(self): | 22 def __init__(self): |
43 ns = namespace | 26 ns = namespace |
44 | 27 |
45 # we need current mercurial named objects (bookmarks, tags, and | 28 # we need current mercurial named objects (bookmarks, tags, and |
46 # branches) to be initialized somewhere, so that place is here | 29 # branches) to be initialized somewhere, so that place is here |
47 n = ns("bookmarks", "bookmark", | 30 n = ns("bookmarks", "bookmark", |
48 lambda repo, name: tolist(repo._bookmarks.get(name)), | 31 lambda repo, name: tolist(repo._bookmarks.get(name)), |
49 lambda repo, name: repo.nodebookmarks(name)) | 32 lambda repo, name: repo.nodebookmarks(name)) |
50 self.addnamespace(n) | 33 self.addnamespace(n) |
51 | 34 |
52 n = ns("tags", "tag", | 35 n = ns("tags", "tag", |
53 lambda repo, name: tolist(repo._tagscache.tags.get(name)), | 36 lambda repo, name: tolist(repo._tagscache.tags.get(name)), |
54 lambda repo, name: repo.nodetags(name)) | 37 lambda repo, name: repo.nodetags(name)) |
55 self.addnamespace(n) | 38 self.addnamespace(n) |
56 | 39 |
57 n = ns("branches", "branch", | 40 n = ns("branches", "branch", |
58 lambda repo, name: tolist(repo.branchtip(name)), | 41 lambda repo, name: tolist(repo.branchtip(name)), |
59 lambda repo, node: [repo[node].branch()]) | 42 lambda repo, node: [repo[node].branch()]) |
60 self.addnamespace(n) | 43 self.addnamespace(n) |
61 | 44 |
62 def addnamespace(self, namespace, order=None): | 45 def addnamespace(self, namespace, order=None): |
63 """ | 46 """register a namespace |
64 register a namespace | |
65 | 47 |
66 namespace: the name to be registered (in plural form) | 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 order: optional argument to specify the order of namespaces | 49 order: optional argument to specify the order of namespaces |
71 (e.g. 'branches' should be listed before 'bookmarks') | 50 (e.g. 'branches' should be listed before 'bookmarks') |
51 | |
72 """ | 52 """ |
73 if order is not None: | 53 if order is not None: |
74 self._names.insert(order, namespace.name, namespace) | 54 self._names.insert(order, namespace.name, namespace) |
75 else: | 55 else: |
76 self._names[namespace.name] = namespace | 56 self._names[namespace.name] = namespace |