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