Mercurial > public > mercurial-scm > hg
comparison mercurial/exthelper.py @ 41046:f5ec93f69171
exthelper: drop fileset/revset/template support for now
Yuya raised concerns about duplicating registrar functionality. There are a
couple of ideas to work around this, which would allow bringing them back, and
then backporting to evolve. For now, I just want to get the subsequent changes
landed before the bulk b'' rewrite makes rebasing too hard.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 22 Dec 2018 22:44:24 -0500 |
parents | c1476d095d57 |
children | 021496277392 |
comparison
equal
deleted
inserted
replaced
41045:c1476d095d57 | 41046:f5ec93f69171 |
---|---|
12 from __future__ import absolute_import | 12 from __future__ import absolute_import |
13 | 13 |
14 from . import ( | 14 from . import ( |
15 commands, | 15 commands, |
16 extensions, | 16 extensions, |
17 fileset as filesetmod, | |
18 registrar, | 17 registrar, |
19 revset as revsetmod, | |
20 templatekw as templatekwmod, | |
21 ) | 18 ) |
22 | 19 |
23 class exthelper(object): | 20 class exthelper(object): |
24 """Helper for modular extension setup | 21 """Helper for modular extension setup |
25 | 22 |
32 def __init__(self): | 29 def __init__(self): |
33 self._uipopulatecallables = [] | 30 self._uipopulatecallables = [] |
34 self._uicallables = [] | 31 self._uicallables = [] |
35 self._extcallables = [] | 32 self._extcallables = [] |
36 self._repocallables = [] | 33 self._repocallables = [] |
37 self._revsetsymbols = [] | |
38 self._filesetsymbols = [] | |
39 self._templatekws = [] | |
40 self._commandwrappers = [] | 34 self._commandwrappers = [] |
41 self._extcommandwrappers = [] | 35 self._extcommandwrappers = [] |
42 self._functionwrappers = [] | 36 self._functionwrappers = [] |
43 self._duckpunchers = [] | 37 self._duckpunchers = [] |
44 self.cmdtable = {} | 38 self.cmdtable = {} |
58 def merge(self, other): | 52 def merge(self, other): |
59 self._uicallables.extend(other._uicallables) | 53 self._uicallables.extend(other._uicallables) |
60 self._uipopulatecallables.extend(other._uipopulatecallables) | 54 self._uipopulatecallables.extend(other._uipopulatecallables) |
61 self._extcallables.extend(other._extcallables) | 55 self._extcallables.extend(other._extcallables) |
62 self._repocallables.extend(other._repocallables) | 56 self._repocallables.extend(other._repocallables) |
63 self._revsetsymbols.extend(other._revsetsymbols) | |
64 self._filesetsymbols.extend(other._filesetsymbols) | |
65 self._templatekws.extend(other._templatekws) | |
66 self._commandwrappers.extend(other._commandwrappers) | 57 self._commandwrappers.extend(other._commandwrappers) |
67 self._extcommandwrappers.extend(other._extcommandwrappers) | 58 self._extcommandwrappers.extend(other._extcommandwrappers) |
68 self._functionwrappers.extend(other._functionwrappers) | 59 self._functionwrappers.extend(other._functionwrappers) |
69 self._duckpunchers.extend(other._duckpunchers) | 60 self._duckpunchers.extend(other._duckpunchers) |
70 self.cmdtable.update(other.cmdtable) | 61 self.cmdtable.update(other.cmdtable) |
123 The following operations belong here: | 114 The following operations belong here: |
124 | 115 |
125 - Changes depending on the status of other extensions. (if | 116 - Changes depending on the status of other extensions. (if |
126 extensions.find('mq')) | 117 extensions.find('mq')) |
127 - Add a global option to all commands | 118 - Add a global option to all commands |
128 - Register revset functions | |
129 """ | 119 """ |
130 knownexts = {} | 120 knownexts = {} |
131 | |
132 revsetpredicate = registrar.revsetpredicate() | |
133 for name, symbol in self._revsetsymbols: | |
134 revsetpredicate(name)(symbol) | |
135 revsetmod.loadpredicate(ui, 'evolve', revsetpredicate) | |
136 | |
137 filesetpredicate = registrar.filesetpredicate() | |
138 for name, symbol in self._filesetsymbols: | |
139 filesetpredicate(name)(symbol) | |
140 # TODO: Figure out the calling extension name | |
141 filesetmod.loadpredicate(ui, 'exthelper', filesetpredicate) | |
142 | |
143 templatekeyword = registrar.templatekeyword() | |
144 for name, kw, requires in self._templatekws: | |
145 if requires is not None: | |
146 templatekeyword(name, requires=requires)(kw) | |
147 else: | |
148 templatekeyword(name)(kw) | |
149 templatekwmod.loadkeyword(ui, 'evolve', templatekeyword) | |
150 | 121 |
151 for ext, command, wrapper, opts in self._extcommandwrappers: | 122 for ext, command, wrapper, opts in self._extcommandwrappers: |
152 if ext not in knownexts: | 123 if ext not in knownexts: |
153 try: | 124 try: |
154 e = extensions.find(ext) | 125 e = extensions.find(ext) |
223 print 'this is reposetup!' | 194 print 'this is reposetup!' |
224 """ | 195 """ |
225 self._repocallables.append(call) | 196 self._repocallables.append(call) |
226 return call | 197 return call |
227 | 198 |
228 def revset(self, symbolname): | |
229 """Decorated function is a revset symbol | |
230 | |
231 The name of the symbol must be given as the decorator argument. | |
232 The symbol is added during `extsetup`. | |
233 | |
234 example:: | |
235 | |
236 @eh.revset('hidden') | |
237 def revsetbabar(repo, subset, x): | |
238 args = revset.getargs(x, 0, 0, 'babar accept no argument') | |
239 return [r for r in subset if 'babar' in repo[r].description()] | |
240 """ | |
241 def dec(symbol): | |
242 self._revsetsymbols.append((symbolname, symbol)) | |
243 return symbol | |
244 return dec | |
245 | |
246 def fileset(self, symbolname): | |
247 """Decorated function is a fileset symbol | |
248 | |
249 The name of the symbol must be given as the decorator argument. | |
250 The symbol is added during `extsetup`. | |
251 | |
252 example:: | |
253 | |
254 @eh.fileset('lfs()') | |
255 def filesetbabar(mctx, x): | |
256 return mctx.predicate(...) | |
257 """ | |
258 def dec(symbol): | |
259 self._filesetsymbols.append((symbolname, symbol)) | |
260 return symbol | |
261 return dec | |
262 | |
263 def templatekw(self, keywordname, requires=None): | |
264 """Decorated function is a template keyword | |
265 | |
266 The name of the keyword must be given as the decorator argument. | |
267 The symbol is added during `extsetup`. | |
268 | |
269 example:: | |
270 | |
271 @eh.templatekw('babar') | |
272 def kwbabar(ctx): | |
273 return 'babar' | |
274 """ | |
275 def dec(keyword): | |
276 self._templatekws.append((keywordname, keyword, requires)) | |
277 return keyword | |
278 return dec | |
279 | |
280 def wrapcommand(self, command, extension=None, opts=None): | 199 def wrapcommand(self, command, extension=None, opts=None): |
281 """Decorated function is a command wrapper | 200 """Decorated function is a command wrapper |
282 | 201 |
283 The name of the command must be given as the decorator argument. | 202 The name of the command must be given as the decorator argument. |
284 The wrapping is installed during `uisetup`. | 203 The wrapping is installed during `uisetup`. |