comparison mercurial/match.py @ 6604:98b6e6f0e49b

match: cleanup match classes a bit
author Matt Mackall <mpm@selenic.com>
date Mon, 12 May 2008 11:37:08 -0500
parents 7fe4610cf920
children cbdfd08eabc9
comparison
equal deleted inserted replaced
6603:41eb20cc1c02 6604:98b6e6f0e49b
1 import util 1 import util
2 2
3 class match(object): 3 class _match(object):
4 def __init__(self, root, cwd, patterns, include, exclude, default): 4 def __init__(self, root, cwd, files, mf, ap):
5 self._patterns = patterns
6 self._root = root 5 self._root = root
7 self._cwd = cwd 6 self._cwd = cwd
8 self._include = include 7 self._files = files
9 self._exclude = exclude 8 self._fmap = dict.fromkeys(files)
10 f, mf, ap = util.matcher(root, cwd, patterns, include, exclude,
11 self.src(), default)
12 self._files = f
13 self._fmap = dict.fromkeys(f)
14 self._matchfn = mf 9 self._matchfn = mf
15 self._anypats = ap 10 self._anypats = ap
16 def src(self):
17 return None
18 def __call__(self, fn): 11 def __call__(self, fn):
19 return self._matchfn(fn) 12 return self._matchfn(fn)
20 def __iter__(self): 13 def __iter__(self):
21 for f in self._files: 14 for f in self._files:
22 yield f 15 yield f
33 def files(self): 26 def files(self):
34 return self._files 27 return self._files
35 def anypats(self): 28 def anypats(self):
36 return self._anypats 29 return self._anypats
37 30
38 def always(root, cwd): 31 class always(_match):
39 return match(root, cwd, [], None, None, 'relpath') 32 def __init__(self, root, cwd):
33 _match.__init__(self, root, cwd, [], lambda f: True, False)
40 34
41 def never(root, cwd): 35 class never(_match):
42 m = match(root, cwd, [], None, None, 'relpath') 36 def __init__(self, root, cwd):
43 m._matchfn = lambda f: False 37 _match.__init__(self, root, cwd, [], lambda f: False, False)
44 return m
45 38
46 def exact(root, cwd, files): 39 class exact(_match):
47 m = always(root, cwd) 40 def __init__(self, root, cwd, files):
48 m._files = files 41 _match.__init__(self, root, cwd, files, lambda f: f in files, False)
49 m._fmap = dict.fromkeys(files) 42
50 m._matchfn = m._fmap.has_key 43 class match(_match):
51 return m 44 def __init__(self, root, cwd, patterns, include, exclude, default):
45 f, mf, ap = util.matcher(root, cwd, patterns, include, exclude,
46 None, default)
47 _match.__init__(self, root, cwd, f, mf, ap)