comparison mercurial/revset.py @ 25706:b7f53c474e2c

revset: port extra() to support keyword arguments This is an example to show how keyword arguments are processed.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 28 Jun 2015 22:57:33 +0900
parents 48919d246a47
children d50677c3bf44
comparison
equal deleted inserted replaced
25705:48919d246a47 25706:b7f53c474e2c
838 838
839 If `value` starts with `re:`, the remainder of the value is treated as 839 If `value` starts with `re:`, the remainder of the value is treated as
840 a regular expression. To match a value that actually starts with `re:`, 840 a regular expression. To match a value that actually starts with `re:`,
841 use the prefix `literal:`. 841 use the prefix `literal:`.
842 """ 842 """
843 843 args = getkwargs(x, 'extra', 'label value')
844 if 'label' not in args:
845 # i18n: "extra" is a keyword
846 raise error.ParseError(_('extra takes at least 1 argument'))
844 # i18n: "extra" is a keyword 847 # i18n: "extra" is a keyword
845 l = getargs(x, 1, 2, _('extra takes at least 1 and at most 2 arguments')) 848 label = getstring(args['label'], _('first argument to extra must be '
846 # i18n: "extra" is a keyword 849 'a string'))
847 label = getstring(l[0], _('first argument to extra must be a string'))
848 value = None 850 value = None
849 851
850 if len(l) > 1: 852 if 'value' in args:
851 # i18n: "extra" is a keyword 853 # i18n: "extra" is a keyword
852 value = getstring(l[1], _('second argument to extra must be a string')) 854 value = getstring(args['value'], _('second argument to extra must be '
855 'a string'))
853 kind, value, matcher = _stringmatcher(value) 856 kind, value, matcher = _stringmatcher(value)
854 857
855 def _matchvalue(r): 858 def _matchvalue(r):
856 extra = repo[r].extra() 859 extra = repo[r].extra()
857 return label in extra and (value is None or matcher(extra[label])) 860 return label in extra and (value is None or matcher(extra[label]))