Found by porting test-minifileset.py to Python 3.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
| hg-reviewers |
Found by porting test-minifileset.py to Python 3.
| Automatic diff as part of commit; lint not applicable. |
| Automatic diff as part of commit; unit tests not applicable. |
| # minifileset.py - a simple language to select files | # minifileset.py - a simple language to select files | ||||
| # | # | ||||
| # Copyright 2017 Facebook, Inc. | # Copyright 2017 Facebook, Inc. | ||||
| # | # | ||||
| # This software may be used and distributed according to the terms of the | # This software may be used and distributed according to the terms of the | ||||
| # GNU General Public License version 2 or any later version. | # GNU General Public License version 2 or any later version. | ||||
| from __future__ import absolute_import | from __future__ import absolute_import | ||||
| from .i18n import _ | from .i18n import _ | ||||
| from . import ( | from . import ( | ||||
| error, | error, | ||||
| fileset, | fileset, | ||||
| pycompat, | |||||
| ) | ) | ||||
| def _compile(tree): | def _compile(tree): | ||||
| if not tree: | if not tree: | ||||
| raise error.ParseError(_("missing argument")) | raise error.ParseError(_("missing argument")) | ||||
| op = tree[0] | op = tree[0] | ||||
| if op in {'symbol', 'string', 'kindpat'}: | if op in {'symbol', 'string', 'kindpat'}: | ||||
| name = fileset.getpattern(tree, {'path'}, _('invalid file pattern')) | name = fileset.getpattern(tree, {'path'}, _('invalid file pattern')) | ||||
| if name.startswith('**'): # file extension test, ex. "**.tar.gz" | if name.startswith('**'): # file extension test, ex. "**.tar.gz" | ||||
| ext = name[2:] | ext = name[2:] | ||||
| for c in ext: | for c in pycompat.bytestr(ext): | ||||
| if c in '*{}[]?/\\': | if c in '*{}[]?/\\': | ||||
| raise error.ParseError(_('reserved character: %s') % c) | raise error.ParseError(_('reserved character: %s') % c) | ||||
| return lambda n, s: n.endswith(ext) | return lambda n, s: n.endswith(ext) | ||||
| elif name.startswith('path:'): # directory or full path test | elif name.startswith('path:'): # directory or full path test | ||||
| p = name[5:] # prefix | p = name[5:] # prefix | ||||
| pl = len(p) | pl = len(p) | ||||
| f = lambda n, s: n.startswith(p) and (len(n) == pl or n[pl] == '/') | f = lambda n, s: n.startswith(p) and (len(n) == pl | ||||
| or n[pl:pl + 1] == '/') | |||||
| return f | return f | ||||
| raise error.ParseError(_("unsupported file pattern: %s") % name, | raise error.ParseError(_("unsupported file pattern: %s") % name, | ||||
| hint=_('paths must be prefixed with "path:"')) | hint=_('paths must be prefixed with "path:"')) | ||||
| elif op == 'or': | elif op == 'or': | ||||
| func1 = _compile(tree[1]) | func1 = _compile(tree[1]) | ||||
| func2 = _compile(tree[2]) | func2 = _compile(tree[2]) | ||||
| return lambda n, s: func1(n, s) or func2(n, s) | return lambda n, s: func1(n, s) or func2(n, s) | ||||
| elif op == 'and': | elif op == 'and': | ||||