mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
match: support reading pattern lists from files
This commit is contained in:
parent
933f43725b
commit
5d527f9378
@ -20,6 +20,11 @@ across path separators and ``{a,b}`` to mean "a or b".
|
||||
To use a Perl/Python regular expression, start a name with ``re:``.
|
||||
Regexp pattern matching is anchored at the root of the repository.
|
||||
|
||||
To read name patterns from a file, use ``listfile:`` or ``listfile0:``.
|
||||
The latter expects null delimited patterns while the former expects line
|
||||
feeds. Each string read from the file is itself treated as a file
|
||||
pattern.
|
||||
|
||||
Plain examples::
|
||||
|
||||
path:foo/bar a name bar in a directory named foo in the root
|
||||
@ -39,3 +44,8 @@ Glob examples::
|
||||
Regexp examples::
|
||||
|
||||
re:.*\.c$ any name ending in ".c", anywhere in the repository
|
||||
|
||||
File examples::
|
||||
|
||||
listfile:list.txt read list from list.txt with one file pattern per line
|
||||
listfile0:list.txt read list from list.txt with null byte delimiters
|
||||
|
@ -161,7 +161,8 @@ def _patsplit(pat, default):
|
||||
actual pattern."""
|
||||
if ':' in pat:
|
||||
kind, val = pat.split(':', 1)
|
||||
if kind in ('re', 'glob', 'path', 'relglob', 'relpath', 'relre'):
|
||||
if kind in ('re', 'glob', 'path', 'relglob', 'relpath', 'relre',
|
||||
'listfile', 'listfile0'):
|
||||
return kind, val
|
||||
return default, pat
|
||||
|
||||
@ -270,6 +271,15 @@ def _normalize(names, default, root, cwd, auditor):
|
||||
name = util.canonpath(root, cwd, name, auditor)
|
||||
elif kind in ('relglob', 'path'):
|
||||
name = util.normpath(name)
|
||||
elif kind in ('listfile', 'listfile0'):
|
||||
delimiter = kind == 'listfile0' and '\0' or '\n'
|
||||
try:
|
||||
files = open(name, 'r').read().split(delimiter)
|
||||
files = [f for f in files if f]
|
||||
except EnvironmentError:
|
||||
raise util.Abort(_("unable to read file list (%s)") % name)
|
||||
pats += _normalize(files, default, root, cwd, auditor)
|
||||
continue
|
||||
|
||||
pats.append((kind, name))
|
||||
return pats
|
||||
|
Loading…
Reference in New Issue
Block a user