Mercurial > hg-stable
comparison mercurial/minifileset.py @ 38845:b9162ea1b815
fileset: extract language processing part to new module (API)
I'll add a couple more functions that work on parsed tree.
% wc -l mercurial/fileset*.py
559 mercurial/fileset.py
135 mercurial/filesetlang.py
694 total
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 22 Jul 2018 15:50:45 +0900 |
parents | d82c4d42b615 |
children | 4fe8d1f077b8 |
comparison
equal
deleted
inserted
replaced
38844:d82c4d42b615 | 38845:b9162ea1b815 |
---|---|
9 | 9 |
10 from .i18n import _ | 10 from .i18n import _ |
11 from . import ( | 11 from . import ( |
12 error, | 12 error, |
13 fileset, | 13 fileset, |
14 filesetlang, | |
14 pycompat, | 15 pycompat, |
15 ) | 16 ) |
16 | 17 |
17 def _sizep(x): | 18 def _sizep(x): |
18 # i18n: "size" is a keyword | 19 # i18n: "size" is a keyword |
19 expr = fileset.getstring(x, _("size requires an expression")) | 20 expr = filesetlang.getstring(x, _("size requires an expression")) |
20 return fileset.sizematcher(expr) | 21 return fileset.sizematcher(expr) |
21 | 22 |
22 def _compile(tree): | 23 def _compile(tree): |
23 if not tree: | 24 if not tree: |
24 raise error.ParseError(_("missing argument")) | 25 raise error.ParseError(_("missing argument")) |
25 op = tree[0] | 26 op = tree[0] |
26 if op in {'symbol', 'string', 'kindpat'}: | 27 if op in {'symbol', 'string', 'kindpat'}: |
27 name = fileset.getpattern(tree, {'path'}, _('invalid file pattern')) | 28 name = filesetlang.getpattern(tree, {'path'}, _('invalid file pattern')) |
28 if name.startswith('**'): # file extension test, ex. "**.tar.gz" | 29 if name.startswith('**'): # file extension test, ex. "**.tar.gz" |
29 ext = name[2:] | 30 ext = name[2:] |
30 for c in pycompat.bytestr(ext): | 31 for c in pycompat.bytestr(ext): |
31 if c in '*{}[]?/\\': | 32 if c in '*{}[]?/\\': |
32 raise error.ParseError(_('reserved character: %s') % c) | 33 raise error.ParseError(_('reserved character: %s') % c) |
55 'all': lambda n, s: True, | 56 'all': lambda n, s: True, |
56 'none': lambda n, s: False, | 57 'none': lambda n, s: False, |
57 'size': lambda n, s: _sizep(tree[2])(s), | 58 'size': lambda n, s: _sizep(tree[2])(s), |
58 } | 59 } |
59 | 60 |
60 name = fileset.getsymbol(tree[1]) | 61 name = filesetlang.getsymbol(tree[1]) |
61 if name in symbols: | 62 if name in symbols: |
62 return symbols[name] | 63 return symbols[name] |
63 | 64 |
64 raise error.UnknownIdentifier(name, symbols.keys()) | 65 raise error.UnknownIdentifier(name, symbols.keys()) |
65 elif op == 'minus': # equivalent to 'x and not y' | 66 elif op == 'minus': # equivalent to 'x and not y' |
85 '(**.php & size(">10MB")) | **.zip | (path:bin & !path:bin/README)' for | 86 '(**.php & size(">10MB")) | **.zip | (path:bin & !path:bin/README)' for |
86 example, will catch all php files whose size is greater than 10 MB, all | 87 example, will catch all php files whose size is greater than 10 MB, all |
87 files whose name ends with ".zip", and all files under "bin" in the repo | 88 files whose name ends with ".zip", and all files under "bin" in the repo |
88 root except for "bin/README". | 89 root except for "bin/README". |
89 """ | 90 """ |
90 tree = fileset.parse(text) | 91 tree = filesetlang.parse(text) |
91 return _compile(tree) | 92 return _compile(tree) |