Mercurial > public > mercurial-scm > hg
comparison mercurial/revsetlang.py @ 35594:468d7a1f6633
revsetlang: catch invalid value passed to formatspec()
The scope of AttributeError is narrowed because it's more likely to be
triggered by mistake.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 01 Apr 2017 17:44:07 +0900 |
parents | 850cd045b1df |
children | 91201737d07a |
comparison
equal
deleted
inserted
replaced
35593:850cd045b1df | 35594:468d7a1f6633 |
---|---|
597 parse(arg) # make sure syntax errors are confined | 597 parse(arg) # make sure syntax errors are confined |
598 return '(%s)' % arg | 598 return '(%s)' % arg |
599 elif c == 'n': | 599 elif c == 'n': |
600 return _quote(node.hex(arg)) | 600 return _quote(node.hex(arg)) |
601 elif c == 'b': | 601 elif c == 'b': |
602 return _quote(arg.branch()) | 602 try: |
603 return _quote(arg.branch()) | |
604 except AttributeError: | |
605 raise TypeError | |
603 raise error.ParseError(_('unexpected revspec format character %s') % c) | 606 raise error.ParseError(_('unexpected revspec format character %s') % c) |
604 | 607 |
605 def listexp(s, t): | 608 def listexp(s, t): |
606 l = len(s) | 609 l = len(s) |
607 if l == 0: | 610 if l == 0: |
613 elif t == 's': | 616 elif t == 's': |
614 return "_list('%s')" % "\0".join(s) | 617 return "_list('%s')" % "\0".join(s) |
615 elif t == 'n': | 618 elif t == 'n': |
616 return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s) | 619 return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s) |
617 elif t == 'b': | 620 elif t == 'b': |
618 return "_list('%s')" % "\0".join(a.branch() for a in s) | 621 try: |
622 return "_list('%s')" % "\0".join(a.branch() for a in s) | |
623 except AttributeError: | |
624 raise TypeError | |
619 | 625 |
620 m = l // 2 | 626 m = l // 2 |
621 return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t)) | 627 return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t)) |
622 | 628 |
623 expr = pycompat.bytestr(expr) | 629 expr = pycompat.bytestr(expr) |
649 pos += 1 | 655 pos += 1 |
650 try: | 656 try: |
651 d = expr[pos] | 657 d = expr[pos] |
652 except IndexError: | 658 except IndexError: |
653 raise error.ParseError(_('incomplete revspec format character')) | 659 raise error.ParseError(_('incomplete revspec format character')) |
654 ret.append(listexp(list(arg), d)) | 660 try: |
661 ret.append(listexp(list(arg), d)) | |
662 except (TypeError, ValueError): | |
663 raise error.ParseError(_('invalid argument for revspec')) | |
655 else: | 664 else: |
656 ret.append(argtype(d, arg)) | 665 try: |
666 ret.append(argtype(d, arg)) | |
667 except (TypeError, ValueError): | |
668 raise error.ParseError(_('invalid argument for revspec')) | |
657 pos += 1 | 669 pos += 1 |
658 | 670 |
659 try: | 671 try: |
660 next(argiter) | 672 next(argiter) |
661 raise error.ParseError(_('too many revspec arguments specified')) | 673 raise error.ParseError(_('too many revspec arguments specified')) |