Mercurial > public > mercurial-scm > hg-stable
diff 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 |
line wrap: on
line diff
--- a/mercurial/fileset.py Thu Jan 04 14:20:58 2018 +0900 +++ b/mercurial/fileset.py Sat Jan 13 15:07:37 2018 +0900 @@ -99,6 +99,11 @@ raise error.ParseError(_("invalid token"), pos) return tree +def getsymbol(x): + if x and x[0] == 'symbol': + return x[1] + raise error.ParseError(_('not a symbol')) + def getstring(x, err): if x and (x[0] == 'string' or x[0] == 'symbol'): return x[1] @@ -225,8 +230,8 @@ return [f for f in mctx.subset if f in s] def func(mctx, a, b): - if a[0] == 'symbol' and a[1] in symbols: - funcname = a[1] + funcname = getsymbol(a) + if funcname in symbols: enabled = mctx._existingenabled mctx._existingenabled = funcname in _existingcallers try: @@ -237,7 +242,7 @@ keep = lambda fn: getattr(fn, '__doc__', None) is not None syms = [s for (s, fn) in symbols.items() if keep(fn)] - raise error.UnknownIdentifier(a[1], syms) + raise error.UnknownIdentifier(funcname, syms) def getlist(x): if not x: