Mercurial > public > mercurial-scm > hg
annotate mercurial/match.py @ 6596:7fe4610cf920
match: add always, never, and exact methods
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 12 May 2008 11:37:08 -0500 |
parents | f242d3684f83 |
children | 98b6e6f0e49b |
rev | line source |
---|---|
6576 | 1 import util |
2 | |
3 class match(object): | |
4 def __init__(self, root, cwd, patterns, include, exclude, default): | |
5 self._patterns = patterns | |
6 self._root = root | |
7 self._cwd = cwd | |
8 self._include = include | |
9 self._exclude = exclude | |
6578
f242d3684f83
walk: begin refactoring badmatch handling
Matt Mackall <mpm@selenic.com>
parents:
6576
diff
changeset
|
10 f, mf, ap = util.matcher(root, cwd, patterns, include, exclude, |
f242d3684f83
walk: begin refactoring badmatch handling
Matt Mackall <mpm@selenic.com>
parents:
6576
diff
changeset
|
11 self.src(), default) |
6576 | 12 self._files = f |
13 self._fmap = dict.fromkeys(f) | |
14 self._matchfn = mf | |
15 self._anypats = ap | |
16 def src(self): | |
17 return None | |
18 def __call__(self, fn): | |
19 return self._matchfn(fn) | |
20 def __iter__(self): | |
21 for f in self._files: | |
22 yield f | |
23 def bad(self, f, msg): | |
24 return True | |
25 def dir(self, f): | |
26 pass | |
27 def missing(self, f): | |
28 pass | |
29 def exact(self, f): | |
30 return f in self._fmap | |
31 def rel(self, f): | |
32 return util.pathto(self._root, self._cwd, f) | |
33 def files(self): | |
34 return self._files | |
35 def anypats(self): | |
36 return self._anypats | |
6596
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
37 |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
38 def always(root, cwd): |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
39 return match(root, cwd, [], None, None, 'relpath') |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
40 |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
41 def never(root, cwd): |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
42 m = match(root, cwd, [], None, None, 'relpath') |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
43 m._matchfn = lambda f: False |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
44 return m |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
45 |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
46 def exact(root, cwd, files): |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
47 m = always(root, cwd) |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
48 m._files = files |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
49 m._fmap = dict.fromkeys(files) |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
50 m._matchfn = m._fmap.has_key |
7fe4610cf920
match: add always, never, and exact methods
Matt Mackall <mpm@selenic.com>
parents:
6578
diff
changeset
|
51 return m |