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