Show More
@@ -593,6 +593,14 b' def _formatlistexp(s, t):' | |||||
593 | m = l // 2 |
|
593 | m = l // 2 | |
594 | return '(%s or %s)' % (_formatlistexp(s[:m], t), _formatlistexp(s[m:], t)) |
|
594 | return '(%s or %s)' % (_formatlistexp(s[:m], t), _formatlistexp(s[m:], t)) | |
595 |
|
595 | |||
|
596 | def _formatparamexp(args, t): | |||
|
597 | return ', '.join(_formatargtype(t, a) for a in args) | |||
|
598 | ||||
|
599 | _formatlistfuncs = { | |||
|
600 | 'l': _formatlistexp, | |||
|
601 | 'p': _formatparamexp, | |||
|
602 | } | |||
|
603 | ||||
596 | def formatspec(expr, *args): |
|
604 | def formatspec(expr, *args): | |
597 | ''' |
|
605 | ''' | |
598 | This is a convenience function for using revsets internally, and |
|
606 | This is a convenience function for using revsets internally, and | |
@@ -608,7 +616,8 b' def formatspec(expr, *args):' | |||||
608 | %n = hex(arg), single-quoted |
|
616 | %n = hex(arg), single-quoted | |
609 | %% = a literal '%' |
|
617 | %% = a literal '%' | |
610 |
|
618 | |||
611 |
Prefixing the type with 'l' specifies a parenthesized list of that type |
|
619 | Prefixing the type with 'l' specifies a parenthesized list of that type, | |
|
620 | and 'p' specifies a list of function parameters of that type. | |||
612 |
|
621 | |||
613 | >>> formatspec(b'%r:: and %lr', b'10 or 11', (b"this()", b"that()")) |
|
622 | >>> formatspec(b'%r:: and %lr', b'10 or 11', (b"this()", b"that()")) | |
614 | '(10 or 11):: and ((this()) or (that()))' |
|
623 | '(10 or 11):: and ((this()) or (that()))' | |
@@ -624,6 +633,8 b' def formatspec(expr, *args):' | |||||
624 | "branch('default')" |
|
633 | "branch('default')" | |
625 | >>> formatspec(b'root(%ls)', [b'a', b'b', b'c', b'd']) |
|
634 | >>> formatspec(b'root(%ls)', [b'a', b'b', b'c', b'd']) | |
626 | "root(_list('a\\\\x00b\\\\x00c\\\\x00d'))" |
|
635 | "root(_list('a\\\\x00b\\\\x00c\\\\x00d'))" | |
|
636 | >>> formatspec(b'sort(%r, %ps)', b':', [b'desc', b'user']) | |||
|
637 | "sort((:), 'desc', 'user')" | |||
627 | >>> formatspec('%ls', ['a', "'"]) |
|
638 | >>> formatspec('%ls', ['a', "'"]) | |
628 | "_list('a\\\\x00\\\\'')" |
|
639 | "_list('a\\\\x00\\\\'')" | |
629 | ''' |
|
640 | ''' | |
@@ -651,7 +662,8 b' def formatspec(expr, *args):' | |||||
651 | arg = next(argiter) |
|
662 | arg = next(argiter) | |
652 | except StopIteration: |
|
663 | except StopIteration: | |
653 | raise error.ParseError(_('missing argument for revspec')) |
|
664 | raise error.ParseError(_('missing argument for revspec')) | |
654 | if d == 'l': |
|
665 | f = _formatlistfuncs.get(d) | |
|
666 | if f: | |||
655 | # a list of some type |
|
667 | # a list of some type | |
656 | pos += 1 |
|
668 | pos += 1 | |
657 | try: |
|
669 | try: | |
@@ -659,7 +671,7 b' def formatspec(expr, *args):' | |||||
659 | except IndexError: |
|
671 | except IndexError: | |
660 | raise error.ParseError(_('incomplete revspec format character')) |
|
672 | raise error.ParseError(_('incomplete revspec format character')) | |
661 | try: |
|
673 | try: | |
662 |
ret.append( |
|
674 | ret.append(f(list(arg), d)) | |
663 | except (TypeError, ValueError): |
|
675 | except (TypeError, ValueError): | |
664 | raise error.ParseError(_('invalid argument for revspec')) |
|
676 | raise error.ParseError(_('invalid argument for revspec')) | |
665 | else: |
|
677 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now