# HG changeset patch # User Yuya Nishihara # Date 1532160814 -32400 # Node ID 73731fa8d1bdeec5a0caa1662b56db851ad70a60 # Parent 61ab546b71c3ef511808bfa9dc22a594e51bf9cf fileset: reorder 'or' expression by weight diff -r 61ab546b71c3 -r 73731fa8d1bd mercurial/filesetlang.py --- a/mercurial/filesetlang.py Sat Aug 04 17:08:33 2018 +0900 +++ b/mercurial/filesetlang.py Sat Jul 21 17:13:34 2018 +0900 @@ -207,6 +207,8 @@ return wb, _optimizeandops(op, tb, ta) if op == 'or': ws, ts = zip(*(_optimize(y) for y in x[1:])) + ts = tuple(it[1] for it in sorted(enumerate(ts), + key=lambda it: ws[it[0]])) return max(ws), (op,) + ts if op == 'list': ws, ts = zip(*(_optimize(y) for y in x[1:])) diff -r 61ab546b71c3 -r 73731fa8d1bd tests/test-fileset.t --- a/tests/test-fileset.t Sat Aug 04 17:08:33 2018 +0900 +++ b/tests/test-fileset.t Sat Jul 21 17:13:34 2018 +0900 @@ -203,6 +203,30 @@ b1 b2 +OR expression should be reordered by weight: + + $ fileset -p optimized -s -r. 'grep("a") or a1 or grep("b") or b2' + * optimized: + (or + (symbol 'a1') + (symbol 'b2') + (func + (symbol 'grep') + (string 'a')) + (func + (symbol 'grep') + (string 'b'))) + * matcher: + , + , + , + ]> + a1 + a2 + b1 + b2 + Use differencematcher for 'x and not y': $ fileset -p optimized -s 'a* and not a1'