Mercurial > public > mercurial-scm > hg
comparison mercurial/parser.py @ 28896:4c76a032ec7e
parser: reorder alias expansion routine to return early
I think it improves readability to move trivial cases first, and unindent
blocks.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 29 Mar 2016 16:19:31 +0900 |
parents | 4bf9ed7a260e |
children | c1f254138f44 |
comparison
equal
deleted
inserted
replaced
28895:4bf9ed7a260e | 28896:4c76a032ec7e |
---|---|
507 @classmethod | 507 @classmethod |
508 def _expand(cls, aliases, tree, expanding, cache): | 508 def _expand(cls, aliases, tree, expanding, cache): |
509 if not isinstance(tree, tuple): | 509 if not isinstance(tree, tuple): |
510 return tree | 510 return tree |
511 a = cls._getalias(aliases, tree) | 511 a = cls._getalias(aliases, tree) |
512 if a is not None: | 512 if a is None: |
513 if a.error: | 513 return tuple(cls._expand(aliases, t, expanding, cache) |
514 raise error.Abort(a.error) | 514 for t in tree) |
515 if a in expanding: | 515 if a.error: |
516 raise error.ParseError(_('infinite expansion of %(section)s ' | 516 raise error.Abort(a.error) |
517 '"%(name)s" detected') | 517 if a in expanding: |
518 % {'section': cls._section, | 518 raise error.ParseError(_('infinite expansion of %(section)s ' |
519 'name': a.name}) | 519 '"%(name)s" detected') |
520 expanding.append(a) | 520 % {'section': cls._section, 'name': a.name}) |
521 if a.name not in cache: | 521 expanding.append(a) |
522 cache[a.name] = cls._expand(aliases, a.replacement, expanding, | 522 if a.name not in cache: |
523 cache) | 523 cache[a.name] = cls._expand(aliases, a.replacement, expanding, |
524 result = cache[a.name] | 524 cache) |
525 expanding.pop() | 525 result = cache[a.name] |
526 if a.args is not None: | 526 expanding.pop() |
527 l = cls._getlist(tree[2]) | 527 if a.args is None: |
528 if len(l) != len(a.args): | 528 return result |
529 raise error.ParseError(_('invalid number of arguments: %d') | 529 l = cls._getlist(tree[2]) |
530 % len(l)) | 530 if len(l) != len(a.args): |
531 l = [cls._expand(aliases, t, [], cache) for t in l] | 531 raise error.ParseError(_('invalid number of arguments: %d') |
532 result = cls._expandargs(result, dict(zip(a.args, l))) | 532 % len(l)) |
533 else: | 533 l = [cls._expand(aliases, t, [], cache) for t in l] |
534 result = tuple(cls._expand(aliases, t, expanding, cache) | 534 return cls._expandargs(result, dict(zip(a.args, l))) |
535 for t in tree) | |
536 return result | |
537 | 535 |
538 @classmethod | 536 @classmethod |
539 def expand(cls, aliases, tree): | 537 def expand(cls, aliases, tree): |
540 """Expand aliases in tree, recursively. | 538 """Expand aliases in tree, recursively. |
541 | 539 |