Mercurial > hg
diff mercurial/minifileset.py @ 35741:73432eee0ac4
fileset: add kind:pat operator
":" isn't taken as a symbol character but an infix operator so we can write
e.g. "path:'foo bar'" as well as "'path:foo bar'". An invalid pattern kind
is rejected in the former form as we know a kind is specified explicitly.
The binding strength is copied from "x:y" range operator of revset. Perhaps
it can be adjusted later if we want to parse "foo:bar()" as "(foo:bar)()",
not "foo:(bar())". We can also add "kind:" postfix operator if we want.
One possible confusion is that the scope of the leading "set:" vs "kind:pat"
operator. The former is consumed by a matcher so applies to the whole fileset
expression:
$ hg files 'set:foo() or kind:bar or baz'
^^^^^^^^^^^^^^^^^^^^^^^^
Whereas the scope of kind:pat operator is narrow:
$ hg files 'set:foo() or kind:bar or baz'
^^^
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 14 Jan 2018 13:29:15 +0900 |
parents | 06a757b9e334 |
children | d5288b966e2f |
line wrap: on
line diff
--- a/mercurial/minifileset.py Sun Jan 14 13:33:56 2018 +0900 +++ b/mercurial/minifileset.py Sun Jan 14 13:29:15 2018 +0900 @@ -17,16 +17,14 @@ if not tree: raise error.ParseError(_("missing argument")) op = tree[0] - if op in {'symbol', 'string'}: - name = fileset.getstring(tree, _('invalid file pattern')) + if op in {'symbol', 'string', 'kindpat'}: + name = fileset.getpattern(tree, {'path'}, _('invalid file pattern')) if name.startswith('**'): # file extension test, ex. "**.tar.gz" ext = name[2:] for c in ext: if c in '*{}[]?/\\': raise error.ParseError(_('reserved character: %s') % c) return lambda n, s: n.endswith(ext) - # TODO: teach fileset about 'path:', so that this can be a symbol and - # not require quoting. elif name.startswith('path:'): # directory or full path test p = name[5:] # prefix pl = len(p) @@ -78,7 +76,7 @@ for prefix test. The ``size()`` predicate is borrowed from filesets to test file size. The predicates ``all()`` and ``none()`` are also supported. - '(**.php & size(">10MB")) | **.zip | ("path:bin" & !"path:bin/README")' for + '(**.php & size(">10MB")) | **.zip | (path:bin & !path:bin/README)' for example, will catch all php files whose size is greater than 10 MB, all files whose name ends with ".zip", and all files under "bin" in the repo root except for "bin/README".