revset: construct arguments of only() against matched tree
Since _isonly() knows the structure of 'revs' and 'bases', it should be
slightly easier to understand than destructuring 'ta' and 'tb'.
--- a/mercurial/revset.py Mon May 02 11:27:26 2016 +0900
+++ b/mercurial/revset.py Mon May 02 11:50:48 2016 +0900
@@ -2072,15 +2072,20 @@
"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 @@
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])