mercurial/match.py
changeset 18713 8728579f6bdc
parent 17425 e95ec38f86b0
child 19107 fcf08023c011
equal deleted inserted replaced
18712:e3ddb4068757 18713:8728579f6bdc
    60         self._root = root
    60         self._root = root
    61         self._cwd = cwd
    61         self._cwd = cwd
    62         self._files = []
    62         self._files = []
    63         self._anypats = bool(include or exclude)
    63         self._anypats = bool(include or exclude)
    64         self._ctx = ctx
    64         self._ctx = ctx
       
    65         self._always = False
    65 
    66 
    66         if include:
    67         if include:
    67             pats = _normalize(include, 'glob', root, cwd, auditor)
    68             pats = _normalize(include, 'glob', root, cwd, auditor)
    68             self.includepat, im = _buildmatch(ctx, pats, '(?:/|$)')
    69             self.includepat, im = _buildmatch(ctx, pats, '(?:/|$)')
    69         if exclude:
    70         if exclude:
   101             else:
   102             else:
   102                 if exclude:
   103                 if exclude:
   103                     m = lambda f: not em(f)
   104                     m = lambda f: not em(f)
   104                 else:
   105                 else:
   105                     m = lambda f: True
   106                     m = lambda f: True
       
   107                     self._always = True
   106 
   108 
   107         self.matchfn = m
   109         self.matchfn = m
   108         self._fmap = set(self._files)
   110         self._fmap = set(self._files)
   109 
   111 
   110     def __call__(self, fn):
   112     def __call__(self, fn):
   128     def files(self):
   130     def files(self):
   129         return self._files
   131         return self._files
   130     def anypats(self):
   132     def anypats(self):
   131         return self._anypats
   133         return self._anypats
   132     def always(self):
   134     def always(self):
   133         return False
   135         return self._always
   134 
   136 
   135 class exact(match):
   137 class exact(match):
   136     def __init__(self, root, cwd, files):
   138     def __init__(self, root, cwd, files):
   137         match.__init__(self, root, cwd, files, exact = True)
   139         match.__init__(self, root, cwd, files, exact = True)
   138 
   140 
   139 class always(match):
   141 class always(match):
   140     def __init__(self, root, cwd):
   142     def __init__(self, root, cwd):
   141         match.__init__(self, root, cwd, [])
   143         match.__init__(self, root, cwd, [])
   142     def always(self):
   144         self._always = True
   143         return True
       
   144 
   145 
   145 class narrowmatcher(match):
   146 class narrowmatcher(match):
   146     """Adapt a matcher to work on a subdirectory only.
   147     """Adapt a matcher to work on a subdirectory only.
   147 
   148 
   148     The paths are remapped to remove/insert the path as needed:
   149     The paths are remapped to remove/insert the path as needed:
   173     def __init__(self, path, matcher):
   174     def __init__(self, path, matcher):
   174         self._root = matcher._root
   175         self._root = matcher._root
   175         self._cwd = matcher._cwd
   176         self._cwd = matcher._cwd
   176         self._path = path
   177         self._path = path
   177         self._matcher = matcher
   178         self._matcher = matcher
       
   179         self._always = matcher._always
   178 
   180 
   179         self._files = [f[len(path) + 1:] for f in matcher._files
   181         self._files = [f[len(path) + 1:] for f in matcher._files
   180                        if f.startswith(path + "/")]
   182                        if f.startswith(path + "/")]
   181         self._anypats = matcher._anypats
   183         self._anypats = matcher._anypats
   182         self.matchfn = lambda fn: matcher.matchfn(self._path + "/" + fn)
   184         self.matchfn = lambda fn: matcher.matchfn(self._path + "/" + fn)