##// END OF EJS Templates
revsetlang: add %p specifier to format list of function arguments...
Yuya Nishihara -
r35615:ed0902e8 default
parent child Browse files
Show More
@@ -593,6 +593,14 b' def _formatlistexp(s, t):'
593 593 m = l // 2
594 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 604 def formatspec(expr, *args):
597 605 '''
598 606 This is a convenience function for using revsets internally, and
@@ -608,7 +616,8 b' def formatspec(expr, *args):'
608 616 %n = hex(arg), single-quoted
609 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 622 >>> formatspec(b'%r:: and %lr', b'10 or 11', (b"this()", b"that()"))
614 623 '(10 or 11):: and ((this()) or (that()))'
@@ -624,6 +633,8 b' def formatspec(expr, *args):'
624 633 "branch('default')"
625 634 >>> formatspec(b'root(%ls)', [b'a', b'b', b'c', b'd'])
626 635 "root(_list('a\\\\x00b\\\\x00c\\\\x00d'))"
636 >>> formatspec(b'sort(%r, %ps)', b':', [b'desc', b'user'])
637 "sort((:), 'desc', 'user')"
627 638 >>> formatspec('%ls', ['a', "'"])
628 639 "_list('a\\\\x00\\\\'')"
629 640 '''
@@ -651,7 +662,8 b' def formatspec(expr, *args):'
651 662 arg = next(argiter)
652 663 except StopIteration:
653 664 raise error.ParseError(_('missing argument for revspec'))
654 if d == 'l':
665 f = _formatlistfuncs.get(d)
666 if f:
655 667 # a list of some type
656 668 pos += 1
657 669 try:
@@ -659,7 +671,7 b' def formatspec(expr, *args):'
659 671 except IndexError:
660 672 raise error.ParseError(_('incomplete revspec format character'))
661 673 try:
662 ret.append(_formatlistexp(list(arg), d))
674 ret.append(f(list(arg), d))
663 675 except (TypeError, ValueError):
664 676 raise error.ParseError(_('invalid argument for revspec'))
665 677 else:
General Comments 0
You need to be logged in to leave comments. Login now