Show More
@@ -3514,7 +3514,7 b' def debugrevspec(ui, repo, expr, **opts)' | |||
|
3514 | 3514 | if newtree != tree: |
|
3515 | 3515 | ui.note("* concatenated:\n", revset.prettyformat(newtree), "\n") |
|
3516 | 3516 | if opts["optimize"]: |
|
3517 |
|
|
|
3517 | optimizedtree = revset.optimize(newtree) | |
|
3518 | 3518 | ui.note("* optimized:\n", revset.prettyformat(optimizedtree), "\n") |
|
3519 | 3519 | func = revset.match(ui, expr, repo) |
|
3520 | 3520 | revs = func(repo) |
@@ -2087,7 +2087,7 b' def _matchonly(revs, bases):' | |||
|
2087 | 2087 | and getstring(bases[1][1], _('not a symbol')) == 'ancestors'): |
|
2088 | 2088 | return ('list', revs[2], bases[1][2]) |
|
2089 | 2089 | |
|
2090 | def optimize(x, small): | |
|
2090 | def _optimize(x, small): | |
|
2091 | 2091 | if x is None: |
|
2092 | 2092 | return 0, x |
|
2093 | 2093 | |
@@ -2097,30 +2097,30 b' def optimize(x, small):' | |||
|
2097 | 2097 | |
|
2098 | 2098 | op = x[0] |
|
2099 | 2099 | if op == 'minus': |
|
2100 | return optimize(('and', x[1], ('not', x[2])), small) | |
|
2100 | return _optimize(('and', x[1], ('not', x[2])), small) | |
|
2101 | 2101 | elif op == 'only': |
|
2102 | 2102 | t = ('func', ('symbol', 'only'), ('list', x[1], x[2])) |
|
2103 | return optimize(t, small) | |
|
2103 | return _optimize(t, small) | |
|
2104 | 2104 | elif op == 'onlypost': |
|
2105 | return optimize(('func', ('symbol', 'only'), x[1]), small) | |
|
2105 | return _optimize(('func', ('symbol', 'only'), x[1]), small) | |
|
2106 | 2106 | elif op == 'dagrangepre': |
|
2107 | return optimize(('func', ('symbol', 'ancestors'), x[1]), small) | |
|
2107 | return _optimize(('func', ('symbol', 'ancestors'), x[1]), small) | |
|
2108 | 2108 | elif op == 'dagrangepost': |
|
2109 | return optimize(('func', ('symbol', 'descendants'), x[1]), small) | |
|
2109 | return _optimize(('func', ('symbol', 'descendants'), x[1]), small) | |
|
2110 | 2110 | elif op == 'rangeall': |
|
2111 | return optimize(('range', ('string', '0'), ('string', 'tip')), small) | |
|
2111 | return _optimize(('range', ('string', '0'), ('string', 'tip')), small) | |
|
2112 | 2112 | elif op == 'rangepre': |
|
2113 | return optimize(('range', ('string', '0'), x[1]), small) | |
|
2113 | return _optimize(('range', ('string', '0'), x[1]), small) | |
|
2114 | 2114 | elif op == 'rangepost': |
|
2115 | return optimize(('range', x[1], ('string', 'tip')), small) | |
|
2115 | return _optimize(('range', x[1], ('string', 'tip')), small) | |
|
2116 | 2116 | elif op == 'negate': |
|
2117 | 2117 | s = getstring(x[1], _("can't negate that")) |
|
2118 | return optimize(('string', '-' + s), small) | |
|
2118 | return _optimize(('string', '-' + s), small) | |
|
2119 | 2119 | elif op in 'string symbol negate': |
|
2120 | 2120 | return smallbonus, x # single revisions are small |
|
2121 | 2121 | elif op == 'and': |
|
2122 | wa, ta = optimize(x[1], True) | |
|
2123 | wb, tb = optimize(x[2], True) | |
|
2122 | wa, ta = _optimize(x[1], True) | |
|
2123 | wb, tb = _optimize(x[2], True) | |
|
2124 | 2124 | w = min(wa, wb) |
|
2125 | 2125 | |
|
2126 | 2126 | # (::x and not ::y)/(not ::y and ::x) have a fast path |
@@ -2146,12 +2146,12 b' def optimize(x, small):' | |||
|
2146 | 2146 | else: |
|
2147 | 2147 | s = '\0'.join(t[1] for w, t in ss) |
|
2148 | 2148 | y = ('func', ('symbol', '_list'), ('string', s)) |
|
2149 | w, t = optimize(y, False) | |
|
2149 | w, t = _optimize(y, False) | |
|
2150 | 2150 | ws.append(w) |
|
2151 | 2151 | ts.append(t) |
|
2152 | 2152 | del ss[:] |
|
2153 | 2153 | for y in x[1:]: |
|
2154 | w, t = optimize(y, False) | |
|
2154 | w, t = _optimize(y, False) | |
|
2155 | 2155 | if t is not None and (t[0] == 'string' or t[0] == 'symbol'): |
|
2156 | 2156 | ss.append((w, t)) |
|
2157 | 2157 | continue |
@@ -2169,34 +2169,34 b' def optimize(x, small):' | |||
|
2169 | 2169 | # Optimize not public() to _notpublic() because we have a fast version |
|
2170 | 2170 | if x[1] == ('func', ('symbol', 'public'), None): |
|
2171 | 2171 | newsym = ('func', ('symbol', '_notpublic'), None) |
|
2172 | o = optimize(newsym, not small) | |
|
2172 | o = _optimize(newsym, not small) | |
|
2173 | 2173 | return o[0], o[1] |
|
2174 | 2174 | else: |
|
2175 | o = optimize(x[1], not small) | |
|
2175 | o = _optimize(x[1], not small) | |
|
2176 | 2176 | return o[0], (op, o[1]) |
|
2177 | 2177 | elif op == 'parentpost': |
|
2178 | o = optimize(x[1], small) | |
|
2178 | o = _optimize(x[1], small) | |
|
2179 | 2179 | return o[0], (op, o[1]) |
|
2180 | 2180 | elif op == 'group': |
|
2181 | return optimize(x[1], small) | |
|
2181 | return _optimize(x[1], small) | |
|
2182 | 2182 | elif op in 'dagrange range parent ancestorspec': |
|
2183 | 2183 | if op == 'parent': |
|
2184 | 2184 | # x^:y means (x^) : y, not x ^ (:y) |
|
2185 | 2185 | post = ('parentpost', x[1]) |
|
2186 | 2186 | if x[2][0] == 'dagrangepre': |
|
2187 | return optimize(('dagrange', post, x[2][1]), small) | |
|
2187 | return _optimize(('dagrange', post, x[2][1]), small) | |
|
2188 | 2188 | elif x[2][0] == 'rangepre': |
|
2189 | return optimize(('range', post, x[2][1]), small) | |
|
2190 | ||
|
2191 | wa, ta = optimize(x[1], small) | |
|
2192 | wb, tb = optimize(x[2], small) | |
|
2189 | return _optimize(('range', post, x[2][1]), small) | |
|
2190 | ||
|
2191 | wa, ta = _optimize(x[1], small) | |
|
2192 | wb, tb = _optimize(x[2], small) | |
|
2193 | 2193 | return wa + wb, (op, ta, tb) |
|
2194 | 2194 | elif op == 'list': |
|
2195 | ws, ts = zip(*(optimize(y, small) for y in x[1:])) | |
|
2195 | ws, ts = zip(*(_optimize(y, small) for y in x[1:])) | |
|
2196 | 2196 | return sum(ws), (op,) + ts |
|
2197 | 2197 | elif op == 'func': |
|
2198 | 2198 | f = getstring(x[1], _("not a symbol")) |
|
2199 | wa, ta = optimize(x[2], small) | |
|
2199 | wa, ta = _optimize(x[2], small) | |
|
2200 | 2200 | if f in ("author branch closed date desc file grep keyword " |
|
2201 | 2201 | "outgoing user"): |
|
2202 | 2202 | w = 10 # slow |
@@ -2215,6 +2215,10 b' def optimize(x, small):' | |||
|
2215 | 2215 | return w + wa, (op, x[1], ta) |
|
2216 | 2216 | return 1, x |
|
2217 | 2217 | |
|
2218 | def optimize(tree): | |
|
2219 | _weight, newtree = _optimize(tree, small=True) | |
|
2220 | return newtree | |
|
2221 | ||
|
2218 | 2222 | # the set of valid characters for the initial letter of symbols in |
|
2219 | 2223 | # alias declarations and definitions |
|
2220 | 2224 | _aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)] |
@@ -2330,7 +2334,7 b' def _makematcher(ui, tree, repo):' | |||
|
2330 | 2334 | if ui: |
|
2331 | 2335 | tree = expandaliases(ui, tree, showwarning=ui.warn) |
|
2332 | 2336 | tree = foldconcat(tree) |
|
2333 |
|
|
|
2337 | tree = optimize(tree) | |
|
2334 | 2338 | posttreebuilthook(tree, repo) |
|
2335 | 2339 | def mfunc(repo, subset=None): |
|
2336 | 2340 | if subset is None: |
@@ -751,7 +751,7 b" def revsingle(repo, revspec, default='.'" | |||
|
751 | 751 | |
|
752 | 752 | def _pairspec(revspec): |
|
753 | 753 | tree = revset.parse(revspec) |
|
754 |
tree = revset.optimize(tree |
|
|
754 | tree = revset.optimize(tree) # fix up "x^:y" -> "(x^):y" | |
|
755 | 755 | return tree and tree[0] in ('range', 'rangepre', 'rangepost', 'rangeall') |
|
756 | 756 | |
|
757 | 757 | def revpair(repo, revs): |
General Comments 0
You need to be logged in to leave comments.
Login now