Revision | 925bc5feba1dad55fc5b12f7b0346e83543f65cd (tree) |
---|---|
Time | 2011-03-28 21:17:03 |
Author | at0fk |
Commiter | at0fk |
Refined narrowclone to use .hgignore pattern
@@ -1,60 +1,62 @@ | ||
1 | 1 | # HG changeset patch |
2 | 2 | # Parent 1e3a1c04ead0c83f18d473e645bb367ca191e93b |
3 | 3 | # User at0fk |
4 | -Narrow cloning | |
5 | - | |
6 | -Supports file in .hg/store/00narrow.i containing regular expression | |
7 | -with exclude pattern. | |
4 | +Narrow cloning | |
5 | + | |
6 | +Supports file in .hg/store/00narrow.i containing regular expressions | |
7 | +with exclude pattern. Same syntax as .hgignore | |
8 | 8 | |
9 | 9 | diff --git a/mercurial/manifest.py b/mercurial/manifest.py |
10 | 10 | --- a/mercurial/manifest.py |
11 | 11 | +++ b/mercurial/manifest.py |
12 | -@@ -8,6 +8,7 @@ | |
12 | +@@ -8,6 +8,8 @@ | |
13 | 13 | from i18n import _ |
14 | 14 | import mdiff, parsers, error, revlog |
15 | 15 | import array, struct |
16 | -+import re | |
16 | ++from ignore import ignorepats | |
17 | ++import match | |
17 | 18 | |
18 | 19 | class manifestdict(dict): |
19 | 20 | def __init__(self, mapping=None, flags=None): |
20 | -@@ -28,10 +29,21 @@ | |
21 | +@@ -28,10 +30,22 @@ | |
21 | 22 | def __init__(self, opener): |
22 | 23 | self._mancache = None |
23 | 24 | revlog.revlog.__init__(self, opener, "00manifest.i") |
24 | 25 | + try: |
25 | -+ self.pattern = re.compile(opener("00narrow.i").read()) | |
26 | ++ pats, warnings = ignorepats(opener("00narrow.i")) | |
27 | ++ self.ignore = match.match('', '', [], pats) | |
26 | 28 | + except: |
27 | -+ self.pattern = None | |
29 | ++ self.ignore = None | |
28 | 30 | |
29 | 31 | def parse(self, lines): |
30 | 32 | mfdict = manifestdict() |
31 | 33 | parsers.parse_manifest(mfdict, mfdict._flags, lines) |
32 | -+ if self.pattern: | |
34 | ++ if self.ignore: | |
33 | 35 | + delete = list() |
34 | -+ for pat in mfdict.keys(): | |
35 | -+ if self.pattern.match(pat): | |
36 | -+ delete.append(pat) | |
37 | -+ for pat in delete: | |
38 | -+ mfdict.pop(pat) | |
36 | ++ for f in mfdict.keys(): | |
37 | ++ if self.ignore(f): | |
38 | ++ delete.append(f) | |
39 | ++ for f in delete: | |
40 | ++ mfdict.pop(f) | |
39 | 41 | return mfdict |
40 | 42 | |
41 | 43 | def readdelta(self, node): |
42 | -@@ -94,6 +106,8 @@ | |
44 | +@@ -94,6 +108,8 @@ | |
43 | 45 | def find(self, node, f): |
44 | 46 | '''look up entry for a single file efficiently. |
45 | 47 | return (node, flags) pair if found, (None, None) if not.''' |
46 | -+ if self.pattern and self.pattern.search(f): | |
48 | ++ if self.ignore and self.ignore(f): | |
47 | 49 | + return None, None |
48 | 50 | if self._mancache and self._mancache[0] == node: |
49 | 51 | return self._mancache[1].get(f), self._mancache[1].flags(f) |
50 | 52 | text = self.revision(node) |
51 | -@@ -120,6 +134,11 @@ | |
53 | +@@ -120,6 +136,11 @@ | |
52 | 54 | for start, end, content in x) |
53 | 55 | |
54 | 56 | def checkforbidden(l): |
55 | -+ if self.pattern: | |
57 | ++ if self.ignore: | |
56 | 58 | + for f in l: |
57 | -+ if self.pattern.search(f): | |
59 | ++ if self.ignore(f): | |
58 | 60 | + raise error.RevlogError( |
59 | 61 | + _("filenames matching narrow pattern disallowed")) |
60 | 62 | for f in l: |