comparison mercurial/revset.py @ 28705:0e4148950e19

revset: remove redundant checks for parsed tree of alias If tree is a tuple, it must have at least one element. Also the length of node tuple is guaranteed by the syntax elements. (e.g. 'func' must have 3 items.) This change will help inlining these trivial functions in future patches.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 29 Feb 2016 16:23:09 +0900
parents a04baf9c063b
children b33ca687c1e3
comparison
equal deleted inserted replaced
28704:1fa6fdb72275 28705:0e4148950e19
333 keyvaluenode='keyvalue', keynode='symbol') 333 keyvaluenode='keyvalue', keynode='symbol')
334 334
335 def isvalidsymbol(tree): 335 def isvalidsymbol(tree):
336 """Examine whether specified ``tree`` is valid ``symbol`` or not 336 """Examine whether specified ``tree`` is valid ``symbol`` or not
337 """ 337 """
338 return tree[0] == 'symbol' and len(tree) > 1 338 return tree[0] == 'symbol'
339 339
340 def getsymbol(tree): 340 def getsymbol(tree):
341 """Get symbol name from valid ``symbol`` in ``tree`` 341 """Get symbol name from valid ``symbol`` in ``tree``
342 342
343 This assumes that ``tree`` is already examined by ``isvalidsymbol``. 343 This assumes that ``tree`` is already examined by ``isvalidsymbol``.
345 return tree[1] 345 return tree[1]
346 346
347 def isvalidfunc(tree): 347 def isvalidfunc(tree):
348 """Examine whether specified ``tree`` is valid ``func`` or not 348 """Examine whether specified ``tree`` is valid ``func`` or not
349 """ 349 """
350 return tree[0] == 'func' and len(tree) > 1 and isvalidsymbol(tree[1]) 350 return tree[0] == 'func' and isvalidsymbol(tree[1])
351 351
352 def getfuncname(tree): 352 def getfuncname(tree):
353 """Get function name from valid ``func`` in ``tree`` 353 """Get function name from valid ``func`` in ``tree``
354 354
355 This assumes that ``tree`` is already examined by ``isvalidfunc``. 355 This assumes that ``tree`` is already examined by ``isvalidfunc``.
359 def getfuncargs(tree): 359 def getfuncargs(tree):
360 """Get list of function arguments from valid ``func`` in ``tree`` 360 """Get list of function arguments from valid ``func`` in ``tree``
361 361
362 This assumes that ``tree`` is already examined by ``isvalidfunc``. 362 This assumes that ``tree`` is already examined by ``isvalidfunc``.
363 """ 363 """
364 if len(tree) > 2: 364 return getlist(tree[2])
365 return getlist(tree[2])
366 else:
367 return []
368 365
369 def getset(repo, subset, x): 366 def getset(repo, subset, x):
370 if not x: 367 if not x:
371 raise error.ParseError(_("missing argument")) 368 raise error.ParseError(_("missing argument"))
372 s = methods[x[0]](repo, subset, *x[1:]) 369 s = methods[x[0]](repo, subset, *x[1:])
2432 2429
2433 def _getalias(aliases, tree): 2430 def _getalias(aliases, tree):
2434 """If tree looks like an unexpanded alias, return it. Return None 2431 """If tree looks like an unexpanded alias, return it. Return None
2435 otherwise. 2432 otherwise.
2436 """ 2433 """
2437 if isinstance(tree, tuple) and tree: 2434 if isinstance(tree, tuple):
2438 if tree[0] == 'symbol' and len(tree) == 2: 2435 if tree[0] == 'symbol':
2439 name = tree[1] 2436 name = tree[1]
2440 alias = aliases.get(name) 2437 alias = aliases.get(name)
2441 if alias and alias.args is None and alias.tree == tree: 2438 if alias and alias.args is None and alias.tree == tree:
2442 return alias 2439 return alias
2443 if tree[0] == 'func' and len(tree) > 1: 2440 if tree[0] == 'func':
2444 if tree[1][0] == 'symbol' and len(tree[1]) == 2: 2441 if tree[1][0] == 'symbol':
2445 name = tree[1][1] 2442 name = tree[1][1]
2446 alias = aliases.get(name) 2443 alias = aliases.get(name)
2447 if alias and alias.args is not None and alias.tree == tree[:2]: 2444 if alias and alias.args is not None and alias.tree == tree[:2]:
2448 return alias 2445 return alias
2449 return None 2446 return None
2450 2447
2451 def _expandargs(tree, args): 2448 def _expandargs(tree, args):
2452 """Replace _aliasarg instances with the substitution value of the 2449 """Replace _aliasarg instances with the substitution value of the
2453 same name in args, recursively. 2450 same name in args, recursively.
2454 """ 2451 """
2455 if not tree or not isinstance(tree, tuple): 2452 if not isinstance(tree, tuple):
2456 return tree 2453 return tree
2457 if tree[0] == '_aliasarg': 2454 if tree[0] == '_aliasarg':
2458 sym = tree[1] 2455 sym = tree[1]
2459 return args[sym] 2456 return args[sym]
2460 return tuple(_expandargs(t, args) for t in tree) 2457 return tuple(_expandargs(t, args) for t in tree)