comparison mercurial/revsetlang.py @ 32931:3292c0df64f7

revsetlang: check arguments passed to ancestors() before optimizing to only() Future patches will add depth parameter to ancestors(), which isn't compatible with only().
author Yuya Nishihara <yuya@tcha.org>
date Sun, 18 Jun 2017 11:57:28 +0900
parents c808507cfbf0
children 4672db164c98
comparison
equal deleted inserted replaced
32930:c808507cfbf0 32931:3292c0df64f7
238 238
239 def _isnamedfunc(x, funcname): 239 def _isnamedfunc(x, funcname):
240 """Check if given tree matches named function""" 240 """Check if given tree matches named function"""
241 return x and x[0] == 'func' and getsymbol(x[1]) == funcname 241 return x and x[0] == 'func' and getsymbol(x[1]) == funcname
242 242
243 def _isposargs(x, n):
244 """Check if given tree is n-length list of positional arguments"""
245 l = getlist(x)
246 return len(l) == n and all(y and y[0] != 'keyvalue' for y in l)
247
243 def _matchnamedfunc(x, funcname): 248 def _matchnamedfunc(x, funcname):
244 """Return args tree if given tree matches named function; otherwise None 249 """Return args tree if given tree matches named function; otherwise None
245 250
246 This can't be used for testing a nullary function since its args tree 251 This can't be used for testing a nullary function since its args tree
247 is also None. Use _isnamedfunc() instead. 252 is also None. Use _isnamedfunc() instead.
300 >>> f('ancestors(A)', 'not ancestors(B)') 305 >>> f('ancestors(A)', 'not ancestors(B)')
301 ('list', ('symbol', 'A'), ('symbol', 'B')) 306 ('list', ('symbol', 'A'), ('symbol', 'B'))
302 """ 307 """
303 ta = _matchnamedfunc(revs, 'ancestors') 308 ta = _matchnamedfunc(revs, 'ancestors')
304 tb = bases and bases[0] == 'not' and _matchnamedfunc(bases[1], 'ancestors') 309 tb = bases and bases[0] == 'not' and _matchnamedfunc(bases[1], 'ancestors')
305 if ta and tb: 310 if _isposargs(ta, 1) and _isposargs(tb, 1):
306 return ('list', ta, tb) 311 return ('list', ta, tb)
307 312
308 def _fixops(x): 313 def _fixops(x):
309 """Rewrite raw parsed tree to resolve ambiguous syntax which cannot be 314 """Rewrite raw parsed tree to resolve ambiguous syntax which cannot be
310 handled well by our simple top-down parser""" 315 handled well by our simple top-down parser"""