Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/fileset.py @ 35691:735f47b41521
fileset: make it robust for bad function calls
Before, it could crash or show cryptic message.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 13 Jan 2018 15:07:37 +0900 |
parents | 0e369eca888f |
children | a62b08f6626b |
comparison
equal
deleted
inserted
replaced
35690:3e394e0558d7 | 35691:735f47b41521 |
---|---|
97 tree, pos = p.parse(tokenize(expr)) | 97 tree, pos = p.parse(tokenize(expr)) |
98 if pos != len(expr): | 98 if pos != len(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] |
105 raise error.ParseError(err) | 110 raise error.ParseError(err) |
106 | 111 |
223 getargs(x, 0, 0, _("clean takes no arguments")) | 228 getargs(x, 0, 0, _("clean takes no arguments")) |
224 s = set(mctx.status().clean) | 229 s = set(mctx.status().clean) |
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: |
233 return symbols[funcname](mctx, b) | 238 return symbols[funcname](mctx, b) |
234 finally: | 239 finally: |
235 mctx._existingenabled = enabled | 240 mctx._existingenabled = enabled |
236 | 241 |
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: |
244 return [] | 249 return [] |
245 if x[0] == 'list': | 250 if x[0] == 'list': |