comparison mercurial/revset.py @ 29117:7828cadd2873

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'.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 02 May 2016 11:50:48 +0900
parents 0c9b05dae010
children 8c295c3b2ce2
comparison
equal deleted inserted replaced
29116:0c9b05dae010 29117:7828cadd2873
2070 "ancestor": ancestorspec, 2070 "ancestor": ancestorspec,
2071 "parent": parentspec, 2071 "parent": parentspec,
2072 "parentpost": p1, 2072 "parentpost": p1,
2073 } 2073 }
2074 2074
2075 def _isonly(revs, bases): 2075 def _matchonly(revs, bases):
2076 return ( 2076 """
2077 revs is not None 2077 >>> f = lambda *args: _matchonly(*map(parse, args))
2078 >>> f('ancestors(A)', 'not ancestors(B)')
2079 ('list', ('symbol', 'A'), ('symbol', 'B'))
2080 """
2081 if (revs is not None
2078 and revs[0] == 'func' 2082 and revs[0] == 'func'
2079 and getstring(revs[1], _('not a symbol')) == 'ancestors' 2083 and getstring(revs[1], _('not a symbol')) == 'ancestors'
2080 and bases is not None 2084 and bases is not None
2081 and bases[0] == 'not' 2085 and bases[0] == 'not'
2082 and bases[1][0] == 'func' 2086 and bases[1][0] == 'func'
2083 and getstring(bases[1][1], _('not a symbol')) == 'ancestors') 2087 and getstring(bases[1][1], _('not a symbol')) == 'ancestors'):
2088 return ('list', revs[2], bases[1][2])
2084 2089
2085 def optimize(x, small): 2090 def optimize(x, small):
2086 if x is None: 2091 if x is None:
2087 return 0, x 2092 return 0, x
2088 2093
2117 wa, ta = optimize(x[1], True) 2122 wa, ta = optimize(x[1], True)
2118 wb, tb = optimize(x[2], True) 2123 wb, tb = optimize(x[2], True)
2119 w = min(wa, wb) 2124 w = min(wa, wb)
2120 2125
2121 # (::x and not ::y)/(not ::y and ::x) have a fast path 2126 # (::x and not ::y)/(not ::y and ::x) have a fast path
2122 if _isonly(ta, tb): 2127 tm = _matchonly(ta, tb) or _matchonly(tb, ta)
2123 return w, ('func', ('symbol', 'only'), ('list', ta[2], tb[1][2])) 2128 if tm:
2124 if _isonly(tb, ta): 2129 return w, ('func', ('symbol', 'only'), tm)
2125 return w, ('func', ('symbol', 'only'), ('list', tb[2], ta[1][2]))
2126 2130
2127 if tb is not None and tb[0] == 'not': 2131 if tb is not None and tb[0] == 'not':
2128 return wa, ('difference', ta, tb[1]) 2132 return wa, ('difference', ta, tb[1])
2129 2133
2130 if wa > wb: 2134 if wa > wb: