[PATCH 2 of 2 V3] fileset: add a lightweight file filtering language
Yuya Nishihara
yuya at tcha.org
Sat Jan 13 05:47:11 UTC 2018
On Fri, 12 Jan 2018 22:21:59 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison at yahoo.com>
> # Date 1515641014 18000
> # Wed Jan 10 22:23:34 2018 -0500
> # Node ID b66e906f11f758eb3b3b0f5bc56cf66229f343b7
> # Parent 2201fc4fd6d3d9dda72459c6642c16acbe6fc0a4
> fileset: add a lightweight file filtering language
Also queued, thanks.
> +def _compile(tree):
> + if not tree:
> + raise error.ParseError(_("missing argument"))
> + op = tree[0]
> + if op == 'symbol':
> + name = fileset.getstring(tree, _('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)
> + else:
> + raise error.ParseError(_('invalid symbol: %s') % name)
> + elif op == 'string':
> + # TODO: teach fileset about 'path:', so that this can be a symbol and
> + # not require quoting.
> + name = fileset.getstring(tree, _('invalid path literal'))
> + if name.startswith('path:'): # directory or full path test
> + p = name[5:] # prefix
> + pl = len(p)
> + f = lambda n, s: n.startswith(p) and (len(n) == pl or n[pl] == '/')
> + return f
> + raise error.ParseError(_("invalid string"),
> + hint=_('paths must be prefixed with "path:"'))
I've moved op == 'string' next to 'symbol' as they'll have to be merged later.
More information about the Mercurial-devel
mailing list