2369 elif op == 'rangepost': |
2369 elif op == 'rangepost': |
2370 return _optimize(('range', x[1], ('string', 'tip')), small) |
2370 return _optimize(('range', x[1], ('string', 'tip')), small) |
2371 elif op == 'negate': |
2371 elif op == 'negate': |
2372 s = getstring(x[1], _("can't negate that")) |
2372 s = getstring(x[1], _("can't negate that")) |
2373 return _optimize(('string', '-' + s), small) |
2373 return _optimize(('string', '-' + s), small) |
2374 elif op in 'string symbol': |
2374 elif op in ('string', 'symbol'): |
2375 return smallbonus, x # single revisions are small |
2375 return smallbonus, x # single revisions are small |
2376 elif op == 'and': |
2376 elif op == 'and': |
2377 wa, ta = _optimize(x[1], True) |
2377 wa, ta = _optimize(x[1], True) |
2378 wb, tb = _optimize(x[2], True) |
2378 wb, tb = _optimize(x[2], True) |
2379 w = min(wa, wb) |
2379 w = min(wa, wb) |
2432 elif op == 'parentpost': |
2432 elif op == 'parentpost': |
2433 o = _optimize(x[1], small) |
2433 o = _optimize(x[1], small) |
2434 return o[0], (op, o[1]) |
2434 return o[0], (op, o[1]) |
2435 elif op == 'group': |
2435 elif op == 'group': |
2436 return _optimize(x[1], small) |
2436 return _optimize(x[1], small) |
2437 elif op in 'dagrange range parent ancestorspec': |
2437 elif op in ('dagrange', 'range', 'parent', 'ancestor'): |
2438 wa, ta = _optimize(x[1], small) |
2438 wa, ta = _optimize(x[1], small) |
2439 wb, tb = _optimize(x[2], small) |
2439 wb, tb = _optimize(x[2], small) |
2440 return wa + wb, (op, ta, tb) |
2440 return wa + wb, (op, ta, tb) |
2441 elif op == 'list': |
2441 elif op == 'list': |
2442 ws, ts = zip(*(_optimize(y, small) for y in x[1:])) |
2442 ws, ts = zip(*(_optimize(y, small) for y in x[1:])) |
2445 w, t = _optimize(x[2], small) |
2445 w, t = _optimize(x[2], small) |
2446 return w, (op, x[1], t) |
2446 return w, (op, x[1], t) |
2447 elif op == 'func': |
2447 elif op == 'func': |
2448 f = getsymbol(x[1]) |
2448 f = getsymbol(x[1]) |
2449 wa, ta = _optimize(x[2], small) |
2449 wa, ta = _optimize(x[2], small) |
2450 if f in ("author branch closed date desc file grep keyword " |
2450 if f in ('author', 'branch', 'closed', 'date', 'desc', 'file', 'grep', |
2451 "outgoing user"): |
2451 'keyword', 'outgoing', 'user'): |
2452 w = 10 # slow |
2452 w = 10 # slow |
2453 elif f in "modifies adds removes": |
2453 elif f in ('modifies', 'adds', 'removes'): |
2454 w = 30 # slower |
2454 w = 30 # slower |
2455 elif f == "contains": |
2455 elif f == "contains": |
2456 w = 100 # very slow |
2456 w = 100 # very slow |
2457 elif f == "ancestor": |
2457 elif f == "ancestor": |
2458 w = 1 * smallbonus |
2458 w = 1 * smallbonus |
2459 elif f in "reverse limit first _intlist": |
2459 elif f in ('reverse', 'limit', 'first', '_intlist'): |
2460 w = 0 |
2460 w = 0 |
2461 elif f in "sort": |
2461 elif f == "sort": |
2462 w = 10 # assume most sorts look at changelog |
2462 w = 10 # assume most sorts look at changelog |
2463 else: |
2463 else: |
2464 w = 1 |
2464 w = 1 |
2465 return w + wa, (op, x[1], ta) |
2465 return w + wa, (op, x[1], ta) |
2466 raise ValueError('invalid operator %r' % op) |
2466 raise ValueError('invalid operator %r' % op) |