--- 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:]))
--- 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:
+ <unionmatcher matchers=[
+ <patternmatcher patterns='(?:a1$)'>,
+ <patternmatcher patterns='(?:b2$)'>,
+ <predicatenmatcher pred=grep('a')>,
+ <predicatenmatcher pred=grep('b')>]>
+ a1
+ a2
+ b1
+ b2
+
Use differencematcher for 'x and not y':
$ fileset -p optimized -s 'a* and not a1'