Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/namespaces.py @ 33060:46fa46608ca5
namespaces: record and expose whether namespace is built-in
Currently, the templating layer tends to treat each namespace
as a one-off, with explicit usage of {bookmarks}, {tags}, {branch},
etc instead of using {namespaces}. It would be really useful if
we could iterate over namespaces and operate on them generically.
However, some consumers may wish to differentiate namespaces by
whether they are built-in to core Mercurial or provided by extensions.
Expected use cases include ignoring non-built-in namespaces or
emitting a generic label for non-built-in namespaces.
This commit introduces an attribute on namespace instances
that says whether the namespace is "built-in" and then exposes
this to the templating layer.
As part of this, we implement a reusable extension for defining
custom names on each changeset for testing. A second consumer
will be introduced in a subsequent commit.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 24 Jun 2017 14:52:15 -0700 |
parents | b98199a5c3e1 |
children | c7b45db8f317 |
comparison
equal
deleted
inserted
replaced
33059:de8e3681c402 | 33060:46fa46608ca5 |
---|---|
33 bmknodemap = lambda repo, node: repo.nodebookmarks(node) | 33 bmknodemap = lambda repo, node: repo.nodebookmarks(node) |
34 n = namespace("bookmarks", templatename="bookmark", | 34 n = namespace("bookmarks", templatename="bookmark", |
35 # i18n: column positioning for "hg log" | 35 # i18n: column positioning for "hg log" |
36 logfmt=_("bookmark: %s\n"), | 36 logfmt=_("bookmark: %s\n"), |
37 listnames=bmknames, | 37 listnames=bmknames, |
38 namemap=bmknamemap, nodemap=bmknodemap) | 38 namemap=bmknamemap, nodemap=bmknodemap, |
39 builtin=True) | |
39 self.addnamespace(n) | 40 self.addnamespace(n) |
40 | 41 |
41 tagnames = lambda repo: [t for t, n in repo.tagslist()] | 42 tagnames = lambda repo: [t for t, n in repo.tagslist()] |
42 tagnamemap = lambda repo, name: tolist(repo._tagscache.tags.get(name)) | 43 tagnamemap = lambda repo, name: tolist(repo._tagscache.tags.get(name)) |
43 tagnodemap = lambda repo, node: repo.nodetags(node) | 44 tagnodemap = lambda repo, node: repo.nodetags(node) |
44 n = namespace("tags", templatename="tag", | 45 n = namespace("tags", templatename="tag", |
45 # i18n: column positioning for "hg log" | 46 # i18n: column positioning for "hg log" |
46 logfmt=_("tag: %s\n"), | 47 logfmt=_("tag: %s\n"), |
47 listnames=tagnames, | 48 listnames=tagnames, |
48 namemap=tagnamemap, nodemap=tagnodemap, | 49 namemap=tagnamemap, nodemap=tagnodemap, |
49 deprecated={'tip'}) | 50 deprecated={'tip'}, |
51 builtin=True) | |
50 self.addnamespace(n) | 52 self.addnamespace(n) |
51 | 53 |
52 bnames = lambda repo: repo.branchmap().keys() | 54 bnames = lambda repo: repo.branchmap().keys() |
53 bnamemap = lambda repo, name: tolist(repo.branchtip(name, True)) | 55 bnamemap = lambda repo, name: tolist(repo.branchtip(name, True)) |
54 bnodemap = lambda repo, node: [repo[node].branch()] | 56 bnodemap = lambda repo, node: [repo[node].branch()] |
55 n = namespace("branches", templatename="branch", | 57 n = namespace("branches", templatename="branch", |
56 # i18n: column positioning for "hg log" | 58 # i18n: column positioning for "hg log" |
57 logfmt=_("branch: %s\n"), | 59 logfmt=_("branch: %s\n"), |
58 listnames=bnames, | 60 listnames=bnames, |
59 namemap=bnamemap, nodemap=bnodemap) | 61 namemap=bnamemap, nodemap=bnodemap, |
62 builtin=True) | |
60 self.addnamespace(n) | 63 self.addnamespace(n) |
61 | 64 |
62 def __getitem__(self, namespace): | 65 def __getitem__(self, namespace): |
63 """returns the namespace object""" | 66 """returns the namespace object""" |
64 return self._names[namespace] | 67 return self._names[namespace] |
132 'listnames': list of all names in the namespace (usually the keys of a | 135 'listnames': list of all names in the namespace (usually the keys of a |
133 dictionary) | 136 dictionary) |
134 'namemap': function that takes a name and returns a list of nodes | 137 'namemap': function that takes a name and returns a list of nodes |
135 'nodemap': function that takes a node and returns a list of names | 138 'nodemap': function that takes a node and returns a list of names |
136 'deprecated': set of names to be masked for ordinary use | 139 'deprecated': set of names to be masked for ordinary use |
137 | 140 'builtin': bool indicating if this namespace is supported by core |
141 Mercurial. | |
138 """ | 142 """ |
139 | 143 |
140 def __init__(self, name, templatename=None, logname=None, colorname=None, | 144 def __init__(self, name, templatename=None, logname=None, colorname=None, |
141 logfmt=None, listnames=None, namemap=None, nodemap=None, | 145 logfmt=None, listnames=None, namemap=None, nodemap=None, |
142 deprecated=None): | 146 deprecated=None, builtin=False): |
143 """create a namespace | 147 """create a namespace |
144 | 148 |
145 name: the namespace to be registered (in plural form) | 149 name: the namespace to be registered (in plural form) |
146 templatename: the name to use for templating | 150 templatename: the name to use for templating |
147 logname: the name to use for log output; if not specified templatename | 151 logname: the name to use for log output; if not specified templatename |
152 it is composed from logname | 156 it is composed from logname |
153 listnames: function to list all names | 157 listnames: function to list all names |
154 namemap: function that inputs a name, output node(s) | 158 namemap: function that inputs a name, output node(s) |
155 nodemap: function that inputs a node, output name(s) | 159 nodemap: function that inputs a node, output name(s) |
156 deprecated: set of names to be masked for ordinary use | 160 deprecated: set of names to be masked for ordinary use |
157 | 161 builtin: whether namespace is implemented by core Mercurial |
158 """ | 162 """ |
159 self.name = name | 163 self.name = name |
160 self.templatename = templatename | 164 self.templatename = templatename |
161 self.logname = logname | 165 self.logname = logname |
162 self.colorname = colorname | 166 self.colorname = colorname |
181 if deprecated is None: | 185 if deprecated is None: |
182 self.deprecated = set() | 186 self.deprecated = set() |
183 else: | 187 else: |
184 self.deprecated = deprecated | 188 self.deprecated = deprecated |
185 | 189 |
190 self.builtin = builtin | |
191 | |
186 def names(self, repo, node): | 192 def names(self, repo, node): |
187 """method that returns a (sorted) list of names in a namespace that | 193 """method that returns a (sorted) list of names in a namespace that |
188 match a given node""" | 194 match a given node""" |
189 return sorted(self.nodemap(repo, node)) | 195 return sorted(self.nodemap(repo, node)) |
190 | 196 |