diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -2072,15 +2072,20 @@ methods = { "parentpost": p1, } -def _isonly(revs, bases): - return ( - revs is not None +def _matchonly(revs, bases): + """ + >>> f = lambda *args: _matchonly(*map(parse, args)) + >>> f('ancestors(A)', 'not ancestors(B)') + ('list', ('symbol', 'A'), ('symbol', 'B')) + """ + if (revs is not None and revs[0] == 'func' and getstring(revs[1], _('not a symbol')) == 'ancestors' and bases is not None and bases[0] == 'not' and bases[1][0] == 'func' - and getstring(bases[1][1], _('not a symbol')) == 'ancestors') + and getstring(bases[1][1], _('not a symbol')) == 'ancestors'): + return ('list', revs[2], bases[1][2]) def optimize(x, small): if x is None: @@ -2119,10 +2124,9 @@ def optimize(x, small): w = min(wa, wb) # (::x and not ::y)/(not ::y and ::x) have a fast path - if _isonly(ta, tb): - return w, ('func', ('symbol', 'only'), ('list', ta[2], tb[1][2])) - if _isonly(tb, ta): - return w, ('func', ('symbol', 'only'), ('list', tb[2], ta[1][2])) + tm = _matchonly(ta, tb) or _matchonly(tb, ta) + if tm: + return w, ('func', ('symbol', 'only'), tm) if tb is not None and tb[0] == 'not': return wa, ('difference', ta, tb[1])