Show More
@@ -229,6 +229,19 b' def parseerrordetail(inst):' | |||||
229 | else: |
|
229 | else: | |
230 | return inst.args[0] |
|
230 | return inst.args[0] | |
231 |
|
231 | |||
|
232 | class alias(object): | |||
|
233 | """Parsed result of alias""" | |||
|
234 | ||||
|
235 | def __init__(self, name, tree, args, err, replacement): | |||
|
236 | self.name = name | |||
|
237 | self.tree = tree | |||
|
238 | self.args = args | |||
|
239 | self.error = err | |||
|
240 | self.replacement = replacement | |||
|
241 | # whether own `error` information is already shown or not. | |||
|
242 | # this avoids showing same warning multiple times at each `findaliases`. | |||
|
243 | self.warned = False | |||
|
244 | ||||
232 | class basealiasrules(object): |
|
245 | class basealiasrules(object): | |
233 | """Parsing and expansion rule set of aliases |
|
246 | """Parsing and expansion rule set of aliases | |
234 |
|
247 | |||
@@ -430,3 +443,22 b' class basealiasrules(object):' | |||||
430 | else: |
|
443 | else: | |
431 | args = set() |
|
444 | args = set() | |
432 | return cls._relabelargs(tree, args) |
|
445 | return cls._relabelargs(tree, args) | |
|
446 | ||||
|
447 | @classmethod | |||
|
448 | def build(cls, decl, defn): | |||
|
449 | """Parse an alias declaration and definition into an alias object""" | |||
|
450 | repl = efmt = None | |||
|
451 | name, tree, args, err = cls._builddecl(decl) | |||
|
452 | if err: | |||
|
453 | efmt = _('failed to parse the declaration of %(section)s ' | |||
|
454 | '"%(name)s": %(error)s') | |||
|
455 | else: | |||
|
456 | try: | |||
|
457 | repl = cls._builddefn(defn, args) | |||
|
458 | except error.ParseError as inst: | |||
|
459 | err = parseerrordetail(inst) | |||
|
460 | efmt = _('failed to parse the definition of %(section)s ' | |||
|
461 | '"%(name)s": %(error)s') | |||
|
462 | if err: | |||
|
463 | err = efmt % {'section': cls._section, 'name': name, 'error': err} | |||
|
464 | return alias(name, tree, args, err, repl) |
@@ -2256,31 +2256,6 b' class _aliasrules(parser.basealiasrules)' | |||||
2256 | _parse = staticmethod(_parsealias) |
|
2256 | _parse = staticmethod(_parsealias) | |
2257 | _getlist = staticmethod(getlist) |
|
2257 | _getlist = staticmethod(getlist) | |
2258 |
|
2258 | |||
2259 | class revsetalias(object): |
|
|||
2260 | # whether own `error` information is already shown or not. |
|
|||
2261 | # this avoids showing same warning multiple times at each `findaliases`. |
|
|||
2262 | warned = False |
|
|||
2263 |
|
||||
2264 | def __init__(self, name, value): |
|
|||
2265 | '''Aliases like: |
|
|||
2266 |
|
||||
2267 | h = heads(default) |
|
|||
2268 | b($1) = ancestors($1) - ancestors(default) |
|
|||
2269 | ''' |
|
|||
2270 | r = _aliasrules._builddecl(name) |
|
|||
2271 | self.name, self.tree, self.args, self.error = r |
|
|||
2272 | if self.error: |
|
|||
2273 | self.error = _('failed to parse the declaration of revset alias' |
|
|||
2274 | ' "%s": %s') % (self.name, self.error) |
|
|||
2275 | return |
|
|||
2276 |
|
||||
2277 | try: |
|
|||
2278 | self.replacement = _aliasrules._builddefn(value, self.args) |
|
|||
2279 | except error.ParseError as inst: |
|
|||
2280 | self.error = _('failed to parse the definition of revset alias' |
|
|||
2281 | ' "%s": %s') % (self.name, |
|
|||
2282 | parser.parseerrordetail(inst)) |
|
|||
2283 |
|
||||
2284 | def _getalias(aliases, tree): |
|
2259 | def _getalias(aliases, tree): | |
2285 | """If tree looks like an unexpanded alias, return it. Return None |
|
2260 | """If tree looks like an unexpanded alias, return it. Return None | |
2286 | otherwise. |
|
2261 | otherwise. | |
@@ -2314,7 +2289,7 b' def _expandaliases(aliases, tree, expand' | |||||
2314 | """Expand aliases in tree, recursively. |
|
2289 | """Expand aliases in tree, recursively. | |
2315 |
|
2290 | |||
2316 | 'aliases' is a dictionary mapping user defined aliases to |
|
2291 | 'aliases' is a dictionary mapping user defined aliases to | |
2317 |
|
|
2292 | alias objects. | |
2318 | """ |
|
2293 | """ | |
2319 | if not isinstance(tree, tuple): |
|
2294 | if not isinstance(tree, tuple): | |
2320 | # Do not expand raw strings |
|
2295 | # Do not expand raw strings | |
@@ -2347,7 +2322,7 b' def _expandaliases(aliases, tree, expand' | |||||
2347 | def findaliases(ui, tree, showwarning=None): |
|
2322 | def findaliases(ui, tree, showwarning=None): | |
2348 | aliases = {} |
|
2323 | aliases = {} | |
2349 | for k, v in ui.configitems('revsetalias'): |
|
2324 | for k, v in ui.configitems('revsetalias'): | |
2350 |
alias = |
|
2325 | alias = _aliasrules.build(k, v) | |
2351 | aliases[alias.name] = alias |
|
2326 | aliases[alias.name] = alias | |
2352 | tree = _expandaliases(aliases, tree, [], {}) |
|
2327 | tree = _expandaliases(aliases, tree, [], {}) | |
2353 | if showwarning: |
|
2328 | if showwarning: |
General Comments 0
You need to be logged in to leave comments.
Login now