mercurial/fileset.py
changeset 38684 07b551a4df44
parent 38613 5cbcbe51d38d
child 38685 80466fd85ac9
equal deleted inserted replaced
38683:ddd2165438cd 38684:07b551a4df44
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from __future__ import absolute_import
     8 from __future__ import absolute_import
     9 
     9 
       
    10 import errno
    10 import re
    11 import re
    11 
    12 
    12 from .i18n import _
    13 from .i18n import _
    13 from . import (
    14 from . import (
    14     error,
    15     error,
   561         self._status = status
   562         self._status = status
   562         self._badfn = badfn
   563         self._badfn = badfn
   563         self._existingenabled = False
   564         self._existingenabled = False
   564     def status(self):
   565     def status(self):
   565         return self._status
   566         return self._status
       
   567 
   566     def matcher(self, patterns):
   568     def matcher(self, patterns):
   567         return self.ctx.match(patterns, badfn=self._badfn)
   569         return self.ctx.match(patterns, badfn=self._badfn)
       
   570 
       
   571     def predicate(self, predfn, predrepr=None, cache=False):
       
   572         """Create a matcher to select files by predfn(filename)"""
       
   573         if cache:
       
   574             predfn = util.cachefunc(predfn)
       
   575         repo = self.ctx.repo()
       
   576         return matchmod.predicatematcher(repo.root, repo.getcwd(), predfn,
       
   577                                          predrepr=predrepr, badfn=self._badfn)
       
   578 
       
   579     def fpredicate(self, predfn, predrepr=None, cache=False):
       
   580         """Create a matcher to select files by predfn(fctx) at the current
       
   581         revision
       
   582 
       
   583         Missing files are ignored.
       
   584         """
       
   585         ctx = self.ctx
       
   586         if ctx.rev() is None:
       
   587             def fctxpredfn(f):
       
   588                 try:
       
   589                     fctx = ctx[f]
       
   590                 except error.LookupError:
       
   591                     return False
       
   592                 try:
       
   593                     fctx.audit()
       
   594                 except error.Abort:
       
   595                     return False
       
   596                 try:
       
   597                     return predfn(fctx)
       
   598                 except (IOError, OSError) as e:
       
   599                     if e.errno in (errno.ENOENT, errno.ENOTDIR, errno.EISDIR):
       
   600                         return False
       
   601                     raise
       
   602         else:
       
   603             def fctxpredfn(f):
       
   604                 try:
       
   605                     fctx = ctx[f]
       
   606                 except error.LookupError:
       
   607                     return False
       
   608                 return predfn(fctx)
       
   609         return self.predicate(fctxpredfn, predrepr=predrepr, cache=cache)
       
   610 
       
   611     def never(self):
       
   612         """Create a matcher to select nothing"""
       
   613         repo = self.ctx.repo()
       
   614         return matchmod.nevermatcher(repo.root, repo.getcwd(),
       
   615                                      badfn=self._badfn)
       
   616 
   568     def filter(self, files):
   617     def filter(self, files):
   569         return [f for f in files if f in self.subset]
   618         return [f for f in files if f in self.subset]
   570     def existing(self):
   619     def existing(self):
   571         if not self._existingenabled:
   620         if not self._existingenabled:
   572             raise error.ProgrammingError('unexpected existing() invocation')
   621             raise error.ProgrammingError('unexpected existing() invocation')