##// END OF EJS Templates
fileset: make it robust for bad function calls...
Yuya Nishihara -
r35709:735f47b4 default
parent child Browse files
Show More
@@ -99,6 +99,11 b' def parse(expr):'
99 raise error.ParseError(_("invalid token"), pos)
99 raise error.ParseError(_("invalid token"), pos)
100 return tree
100 return tree
101
101
102 def getsymbol(x):
103 if x and x[0] == 'symbol':
104 return x[1]
105 raise error.ParseError(_('not a symbol'))
106
102 def getstring(x, err):
107 def getstring(x, err):
103 if x and (x[0] == 'string' or x[0] == 'symbol'):
108 if x and (x[0] == 'string' or x[0] == 'symbol'):
104 return x[1]
109 return x[1]
@@ -225,8 +230,8 b' def clean(mctx, x):'
225 return [f for f in mctx.subset if f in s]
230 return [f for f in mctx.subset if f in s]
226
231
227 def func(mctx, a, b):
232 def func(mctx, a, b):
228 if a[0] == 'symbol' and a[1] in symbols:
233 funcname = getsymbol(a)
229 funcname = a[1]
234 if funcname in symbols:
230 enabled = mctx._existingenabled
235 enabled = mctx._existingenabled
231 mctx._existingenabled = funcname in _existingcallers
236 mctx._existingenabled = funcname in _existingcallers
232 try:
237 try:
@@ -237,7 +242,7 b' def func(mctx, a, b):'
237 keep = lambda fn: getattr(fn, '__doc__', None) is not None
242 keep = lambda fn: getattr(fn, '__doc__', None) is not None
238
243
239 syms = [s for (s, fn) in symbols.items() if keep(fn)]
244 syms = [s for (s, fn) in symbols.items() if keep(fn)]
240 raise error.UnknownIdentifier(a[1], syms)
245 raise error.UnknownIdentifier(funcname, syms)
241
246
242 def getlist(x):
247 def getlist(x):
243 if not x:
248 if not x:
@@ -56,9 +56,8 b' def _compile(tree):'
56 'size': lambda n, s: fileset.sizematcher(tree[2])(s),
56 'size': lambda n, s: fileset.sizematcher(tree[2])(s),
57 }
57 }
58
58
59 x = tree[1]
59 name = fileset.getsymbol(tree[1])
60 name = x[1]
60 if name in symbols:
61 if x[0] == 'symbol' and name in symbols:
62 return symbols[name]
61 return symbols[name]
63
62
64 raise error.UnknownIdentifier(name, symbols.keys())
63 raise error.UnknownIdentifier(name, symbols.keys())
@@ -53,6 +53,22 b' Test operators and basic patterns'
53 hg: parse error: invalid \x escape
53 hg: parse error: invalid \x escape
54 [255]
54 [255]
55
55
56 Test invalid syntax
57
58 $ fileset -v '"added"()'
59 (func
60 (string 'added')
61 None)
62 hg: parse error: not a symbol
63 [255]
64 $ fileset -v '()()'
65 (func
66 (group
67 None)
68 None)
69 hg: parse error: not a symbol
70 [255]
71
56 Test files status
72 Test files status
57
73
58 $ rm a1
74 $ rm a1
General Comments 0
You need to be logged in to leave comments. Login now