Show More
@@ -1,307 +1,310 b'' | |||
|
1 | 1 | # match.py - filename matching |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2008, 2009 Matt Mackall <mpm@selenic.com> and others |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | import re |
|
9 | 9 | import scmutil, util |
|
10 | 10 | from i18n import _ |
|
11 | 11 | |
|
12 | 12 | class match(object): |
|
13 | 13 | def __init__(self, root, cwd, patterns, include=[], exclude=[], |
|
14 | 14 | default='glob', exact=False, auditor=None): |
|
15 | 15 | """build an object to match a set of file patterns |
|
16 | 16 | |
|
17 | 17 | arguments: |
|
18 | 18 | root - the canonical root of the tree you're matching against |
|
19 | 19 | cwd - the current working directory, if relevant |
|
20 | 20 | patterns - patterns to find |
|
21 | 21 | include - patterns to include |
|
22 | 22 | exclude - patterns to exclude |
|
23 | 23 | default - if a pattern in names has no explicit type, assume this one |
|
24 | 24 | exact - patterns are actually literals |
|
25 | 25 | |
|
26 | 26 | a pattern is one of: |
|
27 | 27 | 'glob:<glob>' - a glob relative to cwd |
|
28 | 28 | 're:<regexp>' - a regular expression |
|
29 | 29 | 'path:<path>' - a path relative to canonroot |
|
30 | 30 | 'relglob:<glob>' - an unrooted glob (*.c matches C files in all dirs) |
|
31 | 31 | 'relpath:<path>' - a path relative to cwd |
|
32 | 32 | 'relre:<regexp>' - a regexp that needn't match the start of a name |
|
33 | 33 | '<something>' - a pattern of the specified default type |
|
34 | 34 | """ |
|
35 | 35 | |
|
36 | 36 | self._root = root |
|
37 | 37 | self._cwd = cwd |
|
38 | 38 | self._files = [] |
|
39 | 39 | self._anypats = bool(include or exclude) |
|
40 | 40 | |
|
41 | 41 | if include: |
|
42 | 42 | pats = _normalize(include, 'glob', root, cwd, auditor) |
|
43 | 43 | self.includepat, im = _buildmatch(pats, '(?:/|$)') |
|
44 | 44 | if exclude: |
|
45 | 45 | pats = _normalize(exclude, 'glob', root, cwd, auditor) |
|
46 | 46 | self.excludepat, em = _buildmatch(pats, '(?:/|$)') |
|
47 | 47 | if exact: |
|
48 | 48 | self._files = patterns |
|
49 | 49 | pm = self.exact |
|
50 | 50 | elif patterns: |
|
51 | 51 | pats = _normalize(patterns, default, root, cwd, auditor) |
|
52 | 52 | self._files = _roots(pats) |
|
53 | 53 | self._anypats = self._anypats or _anypats(pats) |
|
54 | 54 | self.patternspat, pm = _buildmatch(pats, '$') |
|
55 | 55 | |
|
56 | 56 | if patterns or exact: |
|
57 | 57 | if include: |
|
58 | 58 | if exclude: |
|
59 | 59 | m = lambda f: im(f) and not em(f) and pm(f) |
|
60 | 60 | else: |
|
61 | 61 | m = lambda f: im(f) and pm(f) |
|
62 | 62 | else: |
|
63 | 63 | if exclude: |
|
64 | 64 | m = lambda f: not em(f) and pm(f) |
|
65 | 65 | else: |
|
66 | 66 | m = pm |
|
67 | 67 | else: |
|
68 | 68 | if include: |
|
69 | 69 | if exclude: |
|
70 | 70 | m = lambda f: im(f) and not em(f) |
|
71 | 71 | else: |
|
72 | 72 | m = im |
|
73 | 73 | else: |
|
74 | 74 | if exclude: |
|
75 | 75 | m = lambda f: not em(f) |
|
76 | 76 | else: |
|
77 | 77 | m = lambda f: True |
|
78 | 78 | |
|
79 | 79 | self.matchfn = m |
|
80 | 80 | self._fmap = set(self._files) |
|
81 | 81 | |
|
82 | 82 | def __call__(self, fn): |
|
83 | 83 | return self.matchfn(fn) |
|
84 | 84 | def __iter__(self): |
|
85 | 85 | for f in self._files: |
|
86 | 86 | yield f |
|
87 | 87 | def bad(self, f, msg): |
|
88 | 88 | '''callback for each explicit file that can't be |
|
89 | 89 | found/accessed, with an error message |
|
90 | 90 | ''' |
|
91 | 91 | pass |
|
92 | 92 | def dir(self, f): |
|
93 | 93 | pass |
|
94 | 94 | def missing(self, f): |
|
95 | 95 | pass |
|
96 | 96 | def exact(self, f): |
|
97 | 97 | return f in self._fmap |
|
98 | 98 | def rel(self, f): |
|
99 | 99 | return util.pathto(self._root, self._cwd, f) |
|
100 | 100 | def files(self): |
|
101 | 101 | return self._files |
|
102 | 102 | def anypats(self): |
|
103 | 103 | return self._anypats |
|
104 | 104 | |
|
105 | 105 | class exact(match): |
|
106 | 106 | def __init__(self, root, cwd, files): |
|
107 | 107 | match.__init__(self, root, cwd, files, exact = True) |
|
108 | 108 | |
|
109 | 109 | class always(match): |
|
110 | 110 | def __init__(self, root, cwd): |
|
111 | 111 | match.__init__(self, root, cwd, []) |
|
112 | 112 | |
|
113 | 113 | class narrowmatcher(match): |
|
114 | 114 | """Adapt a matcher to work on a subdirectory only. |
|
115 | 115 | |
|
116 | 116 | The paths are remapped to remove/insert the path as needed: |
|
117 | 117 | |
|
118 | 118 | >>> m1 = match('root', '', ['a.txt', 'sub/b.txt']) |
|
119 | 119 | >>> m2 = narrowmatcher('sub', m1) |
|
120 | 120 | >>> bool(m2('a.txt')) |
|
121 | 121 | False |
|
122 | 122 | >>> bool(m2('b.txt')) |
|
123 | 123 | True |
|
124 | 124 | >>> bool(m2.matchfn('a.txt')) |
|
125 | 125 | False |
|
126 | 126 | >>> bool(m2.matchfn('b.txt')) |
|
127 | 127 | True |
|
128 | 128 | >>> m2.files() |
|
129 | 129 | ['b.txt'] |
|
130 | 130 | >>> m2.exact('b.txt') |
|
131 | 131 | True |
|
132 | 132 | >>> m2.rel('b.txt') |
|
133 | 133 | 'b.txt' |
|
134 | 134 | >>> def bad(f, msg): |
|
135 | 135 | ... print "%s: %s" % (f, msg) |
|
136 | 136 | >>> m1.bad = bad |
|
137 | 137 | >>> m2.bad('x.txt', 'No such file') |
|
138 | 138 | sub/x.txt: No such file |
|
139 | 139 | """ |
|
140 | 140 | |
|
141 | 141 | def __init__(self, path, matcher): |
|
142 | 142 | self._root = matcher._root |
|
143 | 143 | self._cwd = matcher._cwd |
|
144 | 144 | self._path = path |
|
145 | 145 | self._matcher = matcher |
|
146 | 146 | |
|
147 | 147 | self._files = [f[len(path) + 1:] for f in matcher._files |
|
148 | 148 | if f.startswith(path + "/")] |
|
149 | 149 | self._anypats = matcher._anypats |
|
150 | 150 | self.matchfn = lambda fn: matcher.matchfn(self._path + "/" + fn) |
|
151 | 151 | self._fmap = set(self._files) |
|
152 | 152 | |
|
153 | 153 | def bad(self, f, msg): |
|
154 | 154 | self._matcher.bad(self._path + "/" + f, msg) |
|
155 | 155 | |
|
156 | 156 | def patkind(pat): |
|
157 | 157 | return _patsplit(pat, None)[0] |
|
158 | 158 | |
|
159 | 159 | def _patsplit(pat, default): |
|
160 | 160 | """Split a string into an optional pattern kind prefix and the |
|
161 | 161 | actual pattern.""" |
|
162 | 162 | if ':' in pat: |
|
163 | 163 | kind, val = pat.split(':', 1) |
|
164 | 164 | if kind in ('re', 'glob', 'path', 'relglob', 'relpath', 'relre', |
|
165 | 165 | 'listfile', 'listfile0'): |
|
166 | 166 | return kind, val |
|
167 | 167 | return default, pat |
|
168 | 168 | |
|
169 | 169 | def _globre(pat): |
|
170 | 170 | "convert a glob pattern into a regexp" |
|
171 | 171 | i, n = 0, len(pat) |
|
172 | 172 | res = '' |
|
173 | 173 | group = 0 |
|
174 | 174 | escape = re.escape |
|
175 | 175 | def peek(): |
|
176 | 176 | return i < n and pat[i] |
|
177 | 177 | while i < n: |
|
178 | 178 | c = pat[i] |
|
179 | 179 | i += 1 |
|
180 | 180 | if c not in '*?[{},\\': |
|
181 | 181 | res += escape(c) |
|
182 | 182 | elif c == '*': |
|
183 | 183 | if peek() == '*': |
|
184 | 184 | i += 1 |
|
185 | 185 | res += '.*' |
|
186 | 186 | else: |
|
187 | 187 | res += '[^/]*' |
|
188 | 188 | elif c == '?': |
|
189 | 189 | res += '.' |
|
190 | 190 | elif c == '[': |
|
191 | 191 | j = i |
|
192 | 192 | if j < n and pat[j] in '!]': |
|
193 | 193 | j += 1 |
|
194 | 194 | while j < n and pat[j] != ']': |
|
195 | 195 | j += 1 |
|
196 | 196 | if j >= n: |
|
197 | 197 | res += '\\[' |
|
198 | 198 | else: |
|
199 | 199 | stuff = pat[i:j].replace('\\','\\\\') |
|
200 | 200 | i = j + 1 |
|
201 | 201 | if stuff[0] == '!': |
|
202 | 202 | stuff = '^' + stuff[1:] |
|
203 | 203 | elif stuff[0] == '^': |
|
204 | 204 | stuff = '\\' + stuff |
|
205 | 205 | res = '%s[%s]' % (res, stuff) |
|
206 | 206 | elif c == '{': |
|
207 | 207 | group += 1 |
|
208 | 208 | res += '(?:' |
|
209 | 209 | elif c == '}' and group: |
|
210 | 210 | res += ')' |
|
211 | 211 | group -= 1 |
|
212 | 212 | elif c == ',' and group: |
|
213 | 213 | res += '|' |
|
214 | 214 | elif c == '\\': |
|
215 | 215 | p = peek() |
|
216 | 216 | if p: |
|
217 | 217 | i += 1 |
|
218 | 218 | res += escape(p) |
|
219 | 219 | else: |
|
220 | 220 | res += escape(c) |
|
221 | 221 | else: |
|
222 | 222 | res += escape(c) |
|
223 | 223 | return res |
|
224 | 224 | |
|
225 | 225 | def _regex(kind, name, tail): |
|
226 | 226 | '''convert a pattern into a regular expression''' |
|
227 | 227 | if not name: |
|
228 | 228 | return '' |
|
229 | 229 | if kind == 're': |
|
230 | 230 | return name |
|
231 | 231 | elif kind == 'path': |
|
232 | 232 | return '^' + re.escape(name) + '(?:/|$)' |
|
233 | 233 | elif kind == 'relglob': |
|
234 | 234 | return '(?:|.*/)' + _globre(name) + tail |
|
235 | 235 | elif kind == 'relpath': |
|
236 | 236 | return re.escape(name) + '(?:/|$)' |
|
237 | 237 | elif kind == 'relre': |
|
238 | 238 | if name.startswith('^'): |
|
239 | 239 | return name |
|
240 | 240 | return '.*' + name |
|
241 | 241 | return _globre(name) + tail |
|
242 | 242 | |
|
243 | 243 | def _buildmatch(pats, tail): |
|
244 | 244 | """build a matching function from a set of patterns""" |
|
245 | 245 | try: |
|
246 | 246 | pat = '(?:%s)' % '|'.join([_regex(k, p, tail) for (k, p) in pats]) |
|
247 | 247 | if len(pat) > 20000: |
|
248 | 248 | raise OverflowError() |
|
249 | 249 | return pat, re.compile(pat).match |
|
250 | 250 | except OverflowError: |
|
251 | 251 | # We're using a Python with a tiny regex engine and we |
|
252 | 252 | # made it explode, so we'll divide the pattern list in two |
|
253 | 253 | # until it works |
|
254 | 254 | l = len(pats) |
|
255 | 255 | if l < 2: |
|
256 | 256 | raise |
|
257 | 257 | pata, a = _buildmatch(pats[:l//2], tail) |
|
258 | 258 | patb, b = _buildmatch(pats[l//2:], tail) |
|
259 | 259 | return pat, lambda s: a(s) or b(s) |
|
260 | 260 | except re.error: |
|
261 | 261 | for k, p in pats: |
|
262 | 262 | try: |
|
263 | 263 | re.compile('(?:%s)' % _regex(k, p, tail)) |
|
264 | 264 | except re.error: |
|
265 | 265 | raise util.Abort(_("invalid pattern (%s): %s") % (k, p)) |
|
266 | 266 | raise util.Abort(_("invalid pattern")) |
|
267 | 267 | |
|
268 | 268 | def _normalize(names, default, root, cwd, auditor): |
|
269 | 269 | pats = [] |
|
270 | 270 | for kind, name in [_patsplit(p, default) for p in names]: |
|
271 | 271 | if kind in ('glob', 'relpath'): |
|
272 | 272 | name = scmutil.canonpath(root, cwd, name, auditor) |
|
273 | 273 | elif kind in ('relglob', 'path'): |
|
274 | 274 | name = util.normpath(name) |
|
275 | 275 | elif kind in ('listfile', 'listfile0'): |
|
276 | delimiter = kind == 'listfile0' and '\0' or '\n' | |
|
277 | 276 | try: |
|
278 |
files = util.readfile(name) |
|
|
277 | files = util.readfile(name) | |
|
278 | if kind == 'listfile0': | |
|
279 | files = files.split('\0') | |
|
280 | else: | |
|
281 | files = files.splitlines() | |
|
279 | 282 | files = [f for f in files if f] |
|
280 | 283 | except EnvironmentError: |
|
281 | 284 | raise util.Abort(_("unable to read file list (%s)") % name) |
|
282 | 285 | pats += _normalize(files, default, root, cwd, auditor) |
|
283 | 286 | continue |
|
284 | 287 | |
|
285 | 288 | pats.append((kind, name)) |
|
286 | 289 | return pats |
|
287 | 290 | |
|
288 | 291 | def _roots(patterns): |
|
289 | 292 | r = [] |
|
290 | 293 | for kind, name in patterns: |
|
291 | 294 | if kind == 'glob': # find the non-glob prefix |
|
292 | 295 | root = [] |
|
293 | 296 | for p in name.split('/'): |
|
294 | 297 | if '[' in p or '{' in p or '*' in p or '?' in p: |
|
295 | 298 | break |
|
296 | 299 | root.append(p) |
|
297 | 300 | r.append('/'.join(root) or '.') |
|
298 | 301 | elif kind in ('relpath', 'path'): |
|
299 | 302 | r.append(name or '.') |
|
300 | 303 | elif kind == 'relglob': |
|
301 | 304 | r.append('.') |
|
302 | 305 | return r |
|
303 | 306 | |
|
304 | 307 | def _anypats(patterns): |
|
305 | 308 | for kind, name in patterns: |
|
306 | 309 | if kind in ('glob', 're', 'relglob', 'relre'): |
|
307 | 310 | return True |
@@ -1,306 +1,318 b'' | |||
|
1 | 1 | $ hg init t |
|
2 | 2 | $ cd t |
|
3 | 3 | $ mkdir -p beans |
|
4 | 4 | $ for b in kidney navy turtle borlotti black pinto; do |
|
5 | 5 | > echo $b > beans/$b |
|
6 | 6 | $ done |
|
7 | 7 | $ mkdir -p mammals/Procyonidae |
|
8 | 8 | $ for m in cacomistle coatimundi raccoon; do |
|
9 | 9 | > echo $m > mammals/Procyonidae/$m |
|
10 | 10 | $ done |
|
11 | 11 | $ echo skunk > mammals/skunk |
|
12 | 12 | $ echo fennel > fennel |
|
13 | 13 | $ echo fenugreek > fenugreek |
|
14 | 14 | $ echo fiddlehead > fiddlehead |
|
15 | 15 | $ echo glob:glob > glob:glob |
|
16 | 16 | $ hg addremove |
|
17 | 17 | adding beans/black |
|
18 | 18 | adding beans/borlotti |
|
19 | 19 | adding beans/kidney |
|
20 | 20 | adding beans/navy |
|
21 | 21 | adding beans/pinto |
|
22 | 22 | adding beans/turtle |
|
23 | 23 | adding fennel |
|
24 | 24 | adding fenugreek |
|
25 | 25 | adding fiddlehead |
|
26 | 26 | adding glob:glob |
|
27 | 27 | adding mammals/Procyonidae/cacomistle |
|
28 | 28 | adding mammals/Procyonidae/coatimundi |
|
29 | 29 | adding mammals/Procyonidae/raccoon |
|
30 | 30 | adding mammals/skunk |
|
31 | 31 | warning: filename contains ':', which is reserved on Windows: 'glob:glob' |
|
32 | 32 | $ hg commit -m "commit #0" |
|
33 | 33 | |
|
34 | 34 | $ hg debugwalk |
|
35 | 35 | f beans/black beans/black |
|
36 | 36 | f beans/borlotti beans/borlotti |
|
37 | 37 | f beans/kidney beans/kidney |
|
38 | 38 | f beans/navy beans/navy |
|
39 | 39 | f beans/pinto beans/pinto |
|
40 | 40 | f beans/turtle beans/turtle |
|
41 | 41 | f fennel fennel |
|
42 | 42 | f fenugreek fenugreek |
|
43 | 43 | f fiddlehead fiddlehead |
|
44 | 44 | f glob:glob glob:glob |
|
45 | 45 | f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle |
|
46 | 46 | f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi |
|
47 | 47 | f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon |
|
48 | 48 | f mammals/skunk mammals/skunk |
|
49 | 49 | $ hg debugwalk -I. |
|
50 | 50 | f beans/black beans/black |
|
51 | 51 | f beans/borlotti beans/borlotti |
|
52 | 52 | f beans/kidney beans/kidney |
|
53 | 53 | f beans/navy beans/navy |
|
54 | 54 | f beans/pinto beans/pinto |
|
55 | 55 | f beans/turtle beans/turtle |
|
56 | 56 | f fennel fennel |
|
57 | 57 | f fenugreek fenugreek |
|
58 | 58 | f fiddlehead fiddlehead |
|
59 | 59 | f glob:glob glob:glob |
|
60 | 60 | f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle |
|
61 | 61 | f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi |
|
62 | 62 | f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon |
|
63 | 63 | f mammals/skunk mammals/skunk |
|
64 | 64 | |
|
65 | 65 | $ cd mammals |
|
66 | 66 | $ hg debugwalk |
|
67 | 67 | f beans/black ../beans/black |
|
68 | 68 | f beans/borlotti ../beans/borlotti |
|
69 | 69 | f beans/kidney ../beans/kidney |
|
70 | 70 | f beans/navy ../beans/navy |
|
71 | 71 | f beans/pinto ../beans/pinto |
|
72 | 72 | f beans/turtle ../beans/turtle |
|
73 | 73 | f fennel ../fennel |
|
74 | 74 | f fenugreek ../fenugreek |
|
75 | 75 | f fiddlehead ../fiddlehead |
|
76 | 76 | f glob:glob ../glob:glob |
|
77 | 77 | f mammals/Procyonidae/cacomistle Procyonidae/cacomistle |
|
78 | 78 | f mammals/Procyonidae/coatimundi Procyonidae/coatimundi |
|
79 | 79 | f mammals/Procyonidae/raccoon Procyonidae/raccoon |
|
80 | 80 | f mammals/skunk skunk |
|
81 | 81 | $ hg debugwalk -X ../beans |
|
82 | 82 | f fennel ../fennel |
|
83 | 83 | f fenugreek ../fenugreek |
|
84 | 84 | f fiddlehead ../fiddlehead |
|
85 | 85 | f glob:glob ../glob:glob |
|
86 | 86 | f mammals/Procyonidae/cacomistle Procyonidae/cacomistle |
|
87 | 87 | f mammals/Procyonidae/coatimundi Procyonidae/coatimundi |
|
88 | 88 | f mammals/Procyonidae/raccoon Procyonidae/raccoon |
|
89 | 89 | f mammals/skunk skunk |
|
90 | 90 | $ hg debugwalk -I '*k' |
|
91 | 91 | f mammals/skunk skunk |
|
92 | 92 | $ hg debugwalk -I 'glob:*k' |
|
93 | 93 | f mammals/skunk skunk |
|
94 | 94 | $ hg debugwalk -I 'relglob:*k' |
|
95 | 95 | f beans/black ../beans/black |
|
96 | 96 | f fenugreek ../fenugreek |
|
97 | 97 | f mammals/skunk skunk |
|
98 | 98 | $ hg debugwalk -I 'relglob:*k' . |
|
99 | 99 | f mammals/skunk skunk |
|
100 | 100 | $ hg debugwalk -I 're:.*k$' |
|
101 | 101 | f beans/black ../beans/black |
|
102 | 102 | f fenugreek ../fenugreek |
|
103 | 103 | f mammals/skunk skunk |
|
104 | 104 | $ hg debugwalk -I 'relre:.*k$' |
|
105 | 105 | f beans/black ../beans/black |
|
106 | 106 | f fenugreek ../fenugreek |
|
107 | 107 | f mammals/skunk skunk |
|
108 | 108 | $ hg debugwalk -I 'path:beans' |
|
109 | 109 | f beans/black ../beans/black |
|
110 | 110 | f beans/borlotti ../beans/borlotti |
|
111 | 111 | f beans/kidney ../beans/kidney |
|
112 | 112 | f beans/navy ../beans/navy |
|
113 | 113 | f beans/pinto ../beans/pinto |
|
114 | 114 | f beans/turtle ../beans/turtle |
|
115 | 115 | $ hg debugwalk -I 'relpath:../beans' |
|
116 | 116 | f beans/black ../beans/black |
|
117 | 117 | f beans/borlotti ../beans/borlotti |
|
118 | 118 | f beans/kidney ../beans/kidney |
|
119 | 119 | f beans/navy ../beans/navy |
|
120 | 120 | f beans/pinto ../beans/pinto |
|
121 | 121 | f beans/turtle ../beans/turtle |
|
122 | 122 | $ hg debugwalk . |
|
123 | 123 | f mammals/Procyonidae/cacomistle Procyonidae/cacomistle |
|
124 | 124 | f mammals/Procyonidae/coatimundi Procyonidae/coatimundi |
|
125 | 125 | f mammals/Procyonidae/raccoon Procyonidae/raccoon |
|
126 | 126 | f mammals/skunk skunk |
|
127 | 127 | $ hg debugwalk -I. |
|
128 | 128 | f mammals/Procyonidae/cacomistle Procyonidae/cacomistle |
|
129 | 129 | f mammals/Procyonidae/coatimundi Procyonidae/coatimundi |
|
130 | 130 | f mammals/Procyonidae/raccoon Procyonidae/raccoon |
|
131 | 131 | f mammals/skunk skunk |
|
132 | 132 | $ hg debugwalk Procyonidae |
|
133 | 133 | f mammals/Procyonidae/cacomistle Procyonidae/cacomistle |
|
134 | 134 | f mammals/Procyonidae/coatimundi Procyonidae/coatimundi |
|
135 | 135 | f mammals/Procyonidae/raccoon Procyonidae/raccoon |
|
136 | 136 | |
|
137 | 137 | $ cd Procyonidae |
|
138 | 138 | $ hg debugwalk . |
|
139 | 139 | f mammals/Procyonidae/cacomistle cacomistle |
|
140 | 140 | f mammals/Procyonidae/coatimundi coatimundi |
|
141 | 141 | f mammals/Procyonidae/raccoon raccoon |
|
142 | 142 | $ hg debugwalk .. |
|
143 | 143 | f mammals/Procyonidae/cacomistle cacomistle |
|
144 | 144 | f mammals/Procyonidae/coatimundi coatimundi |
|
145 | 145 | f mammals/Procyonidae/raccoon raccoon |
|
146 | 146 | f mammals/skunk ../skunk |
|
147 | 147 | $ cd .. |
|
148 | 148 | |
|
149 | 149 | $ hg debugwalk ../beans |
|
150 | 150 | f beans/black ../beans/black |
|
151 | 151 | f beans/borlotti ../beans/borlotti |
|
152 | 152 | f beans/kidney ../beans/kidney |
|
153 | 153 | f beans/navy ../beans/navy |
|
154 | 154 | f beans/pinto ../beans/pinto |
|
155 | 155 | f beans/turtle ../beans/turtle |
|
156 | 156 | $ hg debugwalk . |
|
157 | 157 | f mammals/Procyonidae/cacomistle Procyonidae/cacomistle |
|
158 | 158 | f mammals/Procyonidae/coatimundi Procyonidae/coatimundi |
|
159 | 159 | f mammals/Procyonidae/raccoon Procyonidae/raccoon |
|
160 | 160 | f mammals/skunk skunk |
|
161 | 161 | $ hg debugwalk .hg |
|
162 | 162 | abort: path 'mammals/.hg' is inside nested repo 'mammals' |
|
163 | 163 | [255] |
|
164 | 164 | $ hg debugwalk ../.hg |
|
165 | 165 | abort: path contains illegal component: .hg |
|
166 | 166 | [255] |
|
167 | 167 | $ cd .. |
|
168 | 168 | |
|
169 | 169 | $ hg debugwalk -Ibeans |
|
170 | 170 | f beans/black beans/black |
|
171 | 171 | f beans/borlotti beans/borlotti |
|
172 | 172 | f beans/kidney beans/kidney |
|
173 | 173 | f beans/navy beans/navy |
|
174 | 174 | f beans/pinto beans/pinto |
|
175 | 175 | f beans/turtle beans/turtle |
|
176 | 176 | $ hg debugwalk -I '{*,{b,m}*/*}k' |
|
177 | 177 | f beans/black beans/black |
|
178 | 178 | f fenugreek fenugreek |
|
179 | 179 | f mammals/skunk mammals/skunk |
|
180 | 180 | $ hg debugwalk 'glob:mammals/../beans/b*' |
|
181 | 181 | f beans/black beans/black |
|
182 | 182 | f beans/borlotti beans/borlotti |
|
183 | 183 | $ hg debugwalk '-X*/Procyonidae' mammals |
|
184 | 184 | f mammals/skunk mammals/skunk |
|
185 | 185 | $ hg debugwalk path:mammals |
|
186 | 186 | f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle |
|
187 | 187 | f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi |
|
188 | 188 | f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon |
|
189 | 189 | f mammals/skunk mammals/skunk |
|
190 | 190 | $ hg debugwalk .. |
|
191 | 191 | abort: .. not under root |
|
192 | 192 | [255] |
|
193 | 193 | $ hg debugwalk beans/../.. |
|
194 | 194 | abort: beans/../.. not under root |
|
195 | 195 | [255] |
|
196 | 196 | $ hg debugwalk .hg |
|
197 | 197 | abort: path contains illegal component: .hg |
|
198 | 198 | [255] |
|
199 | 199 | $ hg debugwalk beans/../.hg |
|
200 | 200 | abort: path contains illegal component: .hg |
|
201 | 201 | [255] |
|
202 | 202 | $ hg debugwalk beans/../.hg/data |
|
203 | 203 | abort: path contains illegal component: .hg/data |
|
204 | 204 | [255] |
|
205 | 205 | $ hg debugwalk beans/.hg |
|
206 | 206 | abort: path 'beans/.hg' is inside nested repo 'beans' |
|
207 | 207 | [255] |
|
208 | 208 | |
|
209 | 209 | Test absolute paths: |
|
210 | 210 | |
|
211 | 211 | $ hg debugwalk `pwd`/beans |
|
212 | 212 | f beans/black beans/black |
|
213 | 213 | f beans/borlotti beans/borlotti |
|
214 | 214 | f beans/kidney beans/kidney |
|
215 | 215 | f beans/navy beans/navy |
|
216 | 216 | f beans/pinto beans/pinto |
|
217 | 217 | f beans/turtle beans/turtle |
|
218 | 218 | $ hg debugwalk `pwd`/.. |
|
219 | 219 | abort: $TESTTMP/t/.. not under root |
|
220 | 220 | [255] |
|
221 | 221 | |
|
222 | 222 | Test patterns: |
|
223 | 223 | |
|
224 | 224 | $ hg debugwalk glob:\* |
|
225 | 225 | f fennel fennel |
|
226 | 226 | f fenugreek fenugreek |
|
227 | 227 | f fiddlehead fiddlehead |
|
228 | 228 | f glob:glob glob:glob |
|
229 | 229 | |
|
230 | 230 | $ hg debugwalk 'glob:**e' |
|
231 | 231 | f beans/turtle beans/turtle |
|
232 | 232 | f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle |
|
233 | 233 | |
|
234 | 234 | $ hg debugwalk 're:.*[kb]$' |
|
235 | 235 | f beans/black beans/black |
|
236 | 236 | f fenugreek fenugreek |
|
237 | 237 | f glob:glob glob:glob |
|
238 | 238 | f mammals/skunk mammals/skunk |
|
239 | 239 | |
|
240 | 240 | $ hg debugwalk path:beans/black |
|
241 | 241 | f beans/black beans/black exact |
|
242 | 242 | $ hg debugwalk path:beans//black |
|
243 | 243 | f beans/black beans/black exact |
|
244 | 244 | |
|
245 | 245 | $ hg debugwalk relglob:Procyonidae |
|
246 | 246 | $ hg debugwalk 'relglob:Procyonidae/**' |
|
247 | 247 | f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle |
|
248 | 248 | f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi |
|
249 | 249 | f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon |
|
250 | 250 | $ hg debugwalk 'relglob:Procyonidae/**' fennel |
|
251 | 251 | f fennel fennel exact |
|
252 | 252 | f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle |
|
253 | 253 | f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi |
|
254 | 254 | f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon |
|
255 | 255 | $ hg debugwalk beans 'glob:beans/*' |
|
256 | 256 | f beans/black beans/black |
|
257 | 257 | f beans/borlotti beans/borlotti |
|
258 | 258 | f beans/kidney beans/kidney |
|
259 | 259 | f beans/navy beans/navy |
|
260 | 260 | f beans/pinto beans/pinto |
|
261 | 261 | f beans/turtle beans/turtle |
|
262 | 262 | $ hg debugwalk 'glob:mamm**' |
|
263 | 263 | f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle |
|
264 | 264 | f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi |
|
265 | 265 | f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon |
|
266 | 266 | f mammals/skunk mammals/skunk |
|
267 | 267 | $ hg debugwalk 'glob:mamm**' fennel |
|
268 | 268 | f fennel fennel exact |
|
269 | 269 | f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle |
|
270 | 270 | f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi |
|
271 | 271 | f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon |
|
272 | 272 | f mammals/skunk mammals/skunk |
|
273 | 273 | $ hg debugwalk 'glob:j*' |
|
274 | 274 | $ hg debugwalk NOEXIST |
|
275 | 275 | NOEXIST: No such file or directory |
|
276 | 276 | |
|
277 | 277 | $ mkfifo fifo |
|
278 | 278 | $ hg debugwalk fifo |
|
279 | 279 | fifo: unsupported file type (type is fifo) |
|
280 | 280 | |
|
281 | 281 | $ rm fenugreek |
|
282 | 282 | $ hg debugwalk fenugreek |
|
283 | 283 | f fenugreek fenugreek exact |
|
284 | 284 | $ hg rm fenugreek |
|
285 | 285 | $ hg debugwalk fenugreek |
|
286 | 286 | f fenugreek fenugreek exact |
|
287 | 287 | $ touch new |
|
288 | 288 | $ hg debugwalk new |
|
289 | 289 | f new new exact |
|
290 | 290 | |
|
291 | 291 | $ mkdir ignored |
|
292 | 292 | $ touch ignored/file |
|
293 | 293 | $ echo '^ignored$' > .hgignore |
|
294 | 294 | $ hg debugwalk ignored |
|
295 | 295 | $ hg debugwalk ignored/file |
|
296 | 296 | f ignored/file ignored/file exact |
|
297 | 297 | |
|
298 | Test listfile and listfile0 | |
|
299 | ||
|
300 | $ python -c "file('../listfile0', 'wb').write('fenugreek\0new\0')" | |
|
301 | $ hg debugwalk -I 'listfile0:../listfile0' | |
|
302 | f fenugreek fenugreek | |
|
303 | f new new | |
|
304 | $ python -c "file('../listfile', 'wb').write('fenugreek\nnew\r\nmammals/skunk\n')" | |
|
305 | $ hg debugwalk -I 'listfile:../listfile' | |
|
306 | f fenugreek fenugreek | |
|
307 | f mammals/skunk mammals/skunk | |
|
308 | f new new | |
|
309 | ||
|
298 | 310 | $ cd .. |
|
299 | 311 | $ hg debugwalk -R t t/mammals/skunk |
|
300 | 312 | f mammals/skunk t/mammals/skunk exact |
|
301 | 313 | $ mkdir t2 |
|
302 | 314 | $ cd t2 |
|
303 | 315 | $ hg debugwalk -R ../t ../t/mammals/skunk |
|
304 | 316 | f mammals/skunk ../t/mammals/skunk exact |
|
305 | 317 | $ hg debugwalk --cwd ../t mammals/skunk |
|
306 | 318 | f mammals/skunk mammals/skunk exact |
General Comments 0
You need to be logged in to leave comments.
Login now