comparison mercurial/minifileset.py @ 38804:d82c4d42b615

fileset: flatten 'or' nodes to unnest unionmatchers This also makes it easier to compile a union of basic patterns into a single regexp pattern.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 21 Jul 2018 15:23:56 +0900
parents 1500cbe22d53
children b9162ea1b815
comparison
equal deleted inserted replaced
38803:4dc498d61d86 38804:d82c4d42b615
38 or n[pl:pl + 1] == '/') 38 or n[pl:pl + 1] == '/')
39 return f 39 return f
40 raise error.ParseError(_("unsupported file pattern: %s") % name, 40 raise error.ParseError(_("unsupported file pattern: %s") % name,
41 hint=_('paths must be prefixed with "path:"')) 41 hint=_('paths must be prefixed with "path:"'))
42 elif op == 'or': 42 elif op == 'or':
43 func1 = _compile(tree[1]) 43 funcs = [_compile(x) for x in tree[1:]]
44 func2 = _compile(tree[2]) 44 return lambda n, s: any(f(n, s) for f in funcs)
45 return lambda n, s: func1(n, s) or func2(n, s)
46 elif op == 'and': 45 elif op == 'and':
47 func1 = _compile(tree[1]) 46 func1 = _compile(tree[1])
48 func2 = _compile(tree[2]) 47 func2 = _compile(tree[2])
49 return lambda n, s: func1(n, s) and func2(n, s) 48 return lambda n, s: func1(n, s) and func2(n, s)
50 elif op == 'not': 49 elif op == 'not':