31 # we need current mercurial named objects (bookmarks, tags, and |
33 # we need current mercurial named objects (bookmarks, tags, and |
32 # branches) to be initialized somewhere, so that place is here |
34 # branches) to be initialized somewhere, so that place is here |
33 bmknames = lambda repo: repo._bookmarks.keys() |
35 bmknames = lambda repo: repo._bookmarks.keys() |
34 bmknamemap = lambda repo, name: tolist(repo._bookmarks.get(name)) |
36 bmknamemap = lambda repo, name: tolist(repo._bookmarks.get(name)) |
35 bmknodemap = lambda repo, node: repo.nodebookmarks(node) |
37 bmknodemap = lambda repo, node: repo.nodebookmarks(node) |
36 n = namespace("bookmarks", templatename="bookmark", |
38 n = namespace( |
37 logfmt=columns['bookmark'], |
39 "bookmarks", |
38 listnames=bmknames, |
40 templatename="bookmark", |
39 namemap=bmknamemap, nodemap=bmknodemap, |
41 logfmt=columns['bookmark'], |
40 builtin=True) |
42 listnames=bmknames, |
|
43 namemap=bmknamemap, |
|
44 nodemap=bmknodemap, |
|
45 builtin=True, |
|
46 ) |
41 self.addnamespace(n) |
47 self.addnamespace(n) |
42 |
48 |
43 tagnames = lambda repo: [t for t, n in repo.tagslist()] |
49 tagnames = lambda repo: [t for t, n in repo.tagslist()] |
44 tagnamemap = lambda repo, name: tolist(repo._tagscache.tags.get(name)) |
50 tagnamemap = lambda repo, name: tolist(repo._tagscache.tags.get(name)) |
45 tagnodemap = lambda repo, node: repo.nodetags(node) |
51 tagnodemap = lambda repo, node: repo.nodetags(node) |
46 n = namespace("tags", templatename="tag", |
52 n = namespace( |
47 logfmt=columns['tag'], |
53 "tags", |
48 listnames=tagnames, |
54 templatename="tag", |
49 namemap=tagnamemap, nodemap=tagnodemap, |
55 logfmt=columns['tag'], |
50 deprecated={'tip'}, |
56 listnames=tagnames, |
51 builtin=True) |
57 namemap=tagnamemap, |
|
58 nodemap=tagnodemap, |
|
59 deprecated={'tip'}, |
|
60 builtin=True, |
|
61 ) |
52 self.addnamespace(n) |
62 self.addnamespace(n) |
53 |
63 |
54 bnames = lambda repo: repo.branchmap().keys() |
64 bnames = lambda repo: repo.branchmap().keys() |
55 bnamemap = lambda repo, name: tolist(repo.branchtip(name, True)) |
65 bnamemap = lambda repo, name: tolist(repo.branchtip(name, True)) |
56 bnodemap = lambda repo, node: [repo[node].branch()] |
66 bnodemap = lambda repo, node: [repo[node].branch()] |
57 n = namespace("branches", templatename="branch", |
67 n = namespace( |
58 logfmt=columns['branch'], |
68 "branches", |
59 listnames=bnames, |
69 templatename="branch", |
60 namemap=bnamemap, nodemap=bnodemap, |
70 logfmt=columns['branch'], |
61 builtin=True) |
71 listnames=bnames, |
|
72 namemap=bnamemap, |
|
73 nodemap=bnodemap, |
|
74 builtin=True, |
|
75 ) |
62 self.addnamespace(n) |
76 self.addnamespace(n) |
63 |
77 |
64 def __getitem__(self, namespace): |
78 def __getitem__(self, namespace): |
65 """returns the namespace object""" |
79 """returns the namespace object""" |
66 return self._names[namespace] |
80 return self._names[namespace] |
87 self._names[namespace.name] = namespace |
101 self._names[namespace.name] = namespace |
88 |
102 |
89 # we only generate a template keyword if one does not already exist |
103 # we only generate a template keyword if one does not already exist |
90 if namespace.name not in templatekw.keywords: |
104 if namespace.name not in templatekw.keywords: |
91 templatekeyword = registrar.templatekeyword(templatekw.keywords) |
105 templatekeyword = registrar.templatekeyword(templatekw.keywords) |
|
106 |
92 @templatekeyword(namespace.name, requires={'repo', 'ctx'}) |
107 @templatekeyword(namespace.name, requires={'repo', 'ctx'}) |
93 def generatekw(context, mapping): |
108 def generatekw(context, mapping): |
94 return templatekw.shownames(context, mapping, namespace.name) |
109 return templatekw.shownames(context, mapping, namespace.name) |
95 |
110 |
96 def singlenode(self, repo, name): |
111 def singlenode(self, repo, name): |
104 for ns, v in self._names.iteritems(): |
119 for ns, v in self._names.iteritems(): |
105 n = v.singlenode(repo, name) |
120 n = v.singlenode(repo, name) |
106 if n: |
121 if n: |
107 return n |
122 return n |
108 raise KeyError(_('no such name: %s') % name) |
123 raise KeyError(_('no such name: %s') % name) |
|
124 |
109 |
125 |
110 class namespace(object): |
126 class namespace(object): |
111 """provides an interface to a namespace |
127 """provides an interface to a namespace |
112 |
128 |
113 Namespaces are basically generic many-to-many mapping between some |
129 Namespaces are basically generic many-to-many mapping between some |
133 'deprecated': set of names to be masked for ordinary use |
149 'deprecated': set of names to be masked for ordinary use |
134 'builtin': bool indicating if this namespace is supported by core |
150 'builtin': bool indicating if this namespace is supported by core |
135 Mercurial. |
151 Mercurial. |
136 """ |
152 """ |
137 |
153 |
138 def __init__(self, name, templatename=None, logname=None, colorname=None, |
154 def __init__( |
139 logfmt=None, listnames=None, namemap=None, nodemap=None, |
155 self, |
140 deprecated=None, builtin=False, singlenode=None): |
156 name, |
|
157 templatename=None, |
|
158 logname=None, |
|
159 colorname=None, |
|
160 logfmt=None, |
|
161 listnames=None, |
|
162 namemap=None, |
|
163 nodemap=None, |
|
164 deprecated=None, |
|
165 builtin=False, |
|
166 singlenode=None, |
|
167 ): |
141 """create a namespace |
168 """create a namespace |
142 |
169 |
143 name: the namespace to be registered (in plural form) |
170 name: the namespace to be registered (in plural form) |
144 templatename: the name to use for templating |
171 templatename: the name to use for templating |
145 logname: the name to use for log output; if not specified templatename |
172 logname: the name to use for log output; if not specified templatename |