Show More
@@ -140,7 +140,10 b' symbols = {}' | |||
|
140 | 140 | # filesets using matchctx.status() |
|
141 | 141 | _statuscallers = [] |
|
142 | 142 | |
|
143 | def predicate(decl, callstatus=False): | |
|
143 | # filesets using matchctx.existing() | |
|
144 | _existingcallers = [] | |
|
145 | ||
|
146 | def predicate(decl, callstatus=False, callexisting=False): | |
|
144 | 147 | """Return a decorator for fileset predicate function |
|
145 | 148 | |
|
146 | 149 | 'decl' argument is the declaration (including argument list like |
@@ -148,6 +151,10 b' def predicate(decl, callstatus=False):' | |||
|
148 | 151 | |
|
149 | 152 | Optional 'callstatus' argument indicates whether predicate implies |
|
150 | 153 | 'matchctx.status()' at runtime or not (False, by default). |
|
154 | ||
|
155 | Optional 'callexisting' argument indicates whether predicate | |
|
156 | implies 'matchctx.existing()' at runtime or not (False, by | |
|
157 | default). | |
|
151 | 158 | """ |
|
152 | 159 | def decorator(func): |
|
153 | 160 | i = decl.find('(') |
@@ -158,6 +165,8 b' def predicate(decl, callstatus=False):' | |||
|
158 | 165 | symbols[name] = func |
|
159 | 166 | if callstatus: |
|
160 | 167 | _statuscallers.append(name) |
|
168 | if callexisting: | |
|
169 | _existingcallers.append(name) | |
|
161 | 170 | if func.__doc__: |
|
162 | 171 | func.__doc__ = "``%s``\n %s" % (decl, func.__doc__.strip()) |
|
163 | 172 | return func |
@@ -259,7 +268,7 b' def getargs(x, min, max, err):' | |||
|
259 | 268 | raise error.ParseError(err) |
|
260 | 269 | return l |
|
261 | 270 | |
|
262 | @predicate('binary()') | |
|
271 | @predicate('binary()', callexisting=True) | |
|
263 | 272 | def binary(mctx, x): |
|
264 | 273 | """File that appears to be binary (contains NUL bytes). |
|
265 | 274 | """ |
@@ -267,7 +276,7 b' def binary(mctx, x):' | |||
|
267 | 276 | getargs(x, 0, 0, _("binary takes no arguments")) |
|
268 | 277 | return [f for f in mctx.existing() if util.binary(mctx.ctx[f].data())] |
|
269 | 278 | |
|
270 | @predicate('exec()') | |
|
279 | @predicate('exec()', callexisting=True) | |
|
271 | 280 | def exec_(mctx, x): |
|
272 | 281 | """File that is marked as executable. |
|
273 | 282 | """ |
@@ -275,7 +284,7 b' def exec_(mctx, x):' | |||
|
275 | 284 | getargs(x, 0, 0, _("exec takes no arguments")) |
|
276 | 285 | return [f for f in mctx.existing() if mctx.ctx.flags(f) == 'x'] |
|
277 | 286 | |
|
278 | @predicate('symlink()') | |
|
287 | @predicate('symlink()', callexisting=True) | |
|
279 | 288 | def symlink(mctx, x): |
|
280 | 289 | """File that is marked as a symlink. |
|
281 | 290 | """ |
@@ -324,7 +333,7 b' def portable(mctx, x):' | |||
|
324 | 333 | checkwinfilename = util.checkwinfilename |
|
325 | 334 | return [f for f in mctx.subset if checkwinfilename(f) is None] |
|
326 | 335 | |
|
327 | @predicate('grep(regex)') | |
|
336 | @predicate('grep(regex)', callexisting=True) | |
|
328 | 337 | def grep(mctx, x): |
|
329 | 338 | """File contains the given regular expression. |
|
330 | 339 | """ |
@@ -351,7 +360,7 b' def _sizetomax(s):' | |||
|
351 | 360 | except ValueError: |
|
352 | 361 | raise error.ParseError(_("couldn't parse size: %s") % s) |
|
353 | 362 | |
|
354 | @predicate('size(expression)') | |
|
363 | @predicate('size(expression)', callexisting=True) | |
|
355 | 364 | def size(mctx, x): |
|
356 | 365 | """File size matches the given expression. Examples: |
|
357 | 366 | |
@@ -389,7 +398,7 b' def size(mctx, x):' | |||
|
389 | 398 | |
|
390 | 399 | return [f for f in mctx.existing() if m(mctx.ctx[f].size())] |
|
391 | 400 | |
|
392 | @predicate('encoding(name)') | |
|
401 | @predicate('encoding(name)', callexisting=True) | |
|
393 | 402 | def encoding(mctx, x): |
|
394 | 403 | """File can be successfully decoded with the given character |
|
395 | 404 | encoding. May not be useful for encodings other than ASCII and |
@@ -412,7 +421,7 b' def encoding(mctx, x):' | |||
|
412 | 421 | |
|
413 | 422 | return s |
|
414 | 423 | |
|
415 | @predicate('eol(style)') | |
|
424 | @predicate('eol(style)', callexisting=True) | |
|
416 | 425 | def eol(mctx, x): |
|
417 | 426 | """File contains newlines of the given style (dos, unix, mac). Binary |
|
418 | 427 | files are excluded, files with mixed line endings match multiple |
@@ -516,17 +525,6 b' def _intree(funcs, tree):' | |||
|
516 | 525 | return True |
|
517 | 526 | return False |
|
518 | 527 | |
|
519 | # filesets using matchctx.existing() | |
|
520 | _existingcallers = [ | |
|
521 | 'binary', | |
|
522 | 'encoding', | |
|
523 | 'eol', | |
|
524 | 'exec', | |
|
525 | 'grep', | |
|
526 | 'size', | |
|
527 | 'symlink', | |
|
528 | ] | |
|
529 | ||
|
530 | 528 | def getfileset(ctx, expr): |
|
531 | 529 | tree = parse(expr) |
|
532 | 530 |
General Comments 0
You need to be logged in to leave comments.
Login now