Skip to content
Snippets Groups Projects
Commit 07b551a4 authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

fileset: add helpers to make predicatematcher and nevermatcher

These functions will be used to compose a tree of matchers from a fileset
expression.
parent ddd21654
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@
from __future__ import absolute_import
import errno
import re
from .i18n import _
......@@ -563,5 +564,6 @@
self._existingenabled = False
def status(self):
return self._status
def matcher(self, patterns):
return self.ctx.match(patterns, badfn=self._badfn)
......@@ -566,5 +568,52 @@
def matcher(self, patterns):
return self.ctx.match(patterns, badfn=self._badfn)
def predicate(self, predfn, predrepr=None, cache=False):
"""Create a matcher to select files by predfn(filename)"""
if cache:
predfn = util.cachefunc(predfn)
repo = self.ctx.repo()
return matchmod.predicatematcher(repo.root, repo.getcwd(), predfn,
predrepr=predrepr, badfn=self._badfn)
def fpredicate(self, predfn, predrepr=None, cache=False):
"""Create a matcher to select files by predfn(fctx) at the current
revision
Missing files are ignored.
"""
ctx = self.ctx
if ctx.rev() is None:
def fctxpredfn(f):
try:
fctx = ctx[f]
except error.LookupError:
return False
try:
fctx.audit()
except error.Abort:
return False
try:
return predfn(fctx)
except (IOError, OSError) as e:
if e.errno in (errno.ENOENT, errno.ENOTDIR, errno.EISDIR):
return False
raise
else:
def fctxpredfn(f):
try:
fctx = ctx[f]
except error.LookupError:
return False
return predfn(fctx)
return self.predicate(fctxpredfn, predrepr=predrepr, cache=cache)
def never(self):
"""Create a matcher to select nothing"""
repo = self.ctx.repo()
return matchmod.nevermatcher(repo.root, repo.getcwd(),
badfn=self._badfn)
def filter(self, files):
return [f for f in files if f in self.subset]
def existing(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment