Mercurial > hg
changeset 32913: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 | 577759ef2ed2 |
files | mercurial/revsetlang.py tests/test-revset.t |
diffstat | 2 files changed, 65 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revsetlang.py Sun Jun 18 11:39:03 2017 +0900 +++ b/mercurial/revsetlang.py Sun Jun 18 11:57:28 2017 +0900 @@ -240,6 +240,11 @@ """Check if given tree matches named function""" return x and x[0] == 'func' and getsymbol(x[1]) == funcname +def _isposargs(x, n): + """Check if given tree is n-length list of positional arguments""" + l = getlist(x) + return len(l) == n and all(y and y[0] != 'keyvalue' for y in l) + def _matchnamedfunc(x, funcname): """Return args tree if given tree matches named function; otherwise None @@ -302,7 +307,7 @@ """ ta = _matchnamedfunc(revs, 'ancestors') tb = bases and bases[0] == 'not' and _matchnamedfunc(bases[1], 'ancestors') - if ta and tb: + if _isposargs(ta, 1) and _isposargs(tb, 1): return ('list', ta, tb) def _fixops(x):
--- a/tests/test-revset.t Sun Jun 18 11:39:03 2017 +0900 +++ b/tests/test-revset.t Sun Jun 18 11:57:28 2017 +0900 @@ -2980,6 +2980,65 @@ hg: parse error: missing argument [255] +optimization to only() works only if ancestors() takes only one argument + + $ hg debugrevspec -p optimized 'ancestors(6) - ancestors(4, 1)' + * optimized: + (difference + (func + ('symbol', 'ancestors') + ('symbol', '6') + define) + (func + ('symbol', 'ancestors') + (list + ('symbol', '4') + ('symbol', '1')) + any) + define) + hg: parse error: can't use a list in this context + (see hg help "revsets.x or y") + [255] + $ hg debugrevspec -p optimized 'ancestors(6, 1) - ancestors(4)' + * optimized: + (difference + (func + ('symbol', 'ancestors') + (list + ('symbol', '6') + ('symbol', '1')) + define) + (func + ('symbol', 'ancestors') + ('symbol', '4') + any) + define) + hg: parse error: can't use a list in this context + (see hg help "revsets.x or y") + [255] + +optimization disabled if keyword arguments passed (because we're too lazy +to support it) + + $ hg debugrevspec -p optimized 'ancestors(set=6) - ancestors(set=4)' + * optimized: + (difference + (func + ('symbol', 'ancestors') + (keyvalue + ('symbol', 'set') + ('symbol', '6')) + define) + (func + ('symbol', 'ancestors') + (keyvalue + ('symbol', 'set') + ('symbol', '4')) + any) + define) + hg: parse error: can't use a key-value pair in this context + [255] + invalid function call should not be optimized to only() $ log '"ancestors"(6) and not ancestors(4)'