Mercurial > public > mercurial-scm > hg
comparison mercurial/fileset.py @ 38687:1500cbe22d53
fileset: parse argument of size() by predicate function
This change is necessary to pass in a size expression to predicatematcher.
See the next patch.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 10 Jun 2018 20:58:10 +0900 |
parents | 131aae58a316 |
children | ff5b6fca1082 |
comparison
equal
deleted
inserted
replaced
38686:131aae58a316 | 38687:1500cbe22d53 |
---|---|
382 # no extension, this is a precise value | 382 # no extension, this is a precise value |
383 return int(s) | 383 return int(s) |
384 except ValueError: | 384 except ValueError: |
385 raise error.ParseError(_("couldn't parse size: %s") % s) | 385 raise error.ParseError(_("couldn't parse size: %s") % s) |
386 | 386 |
387 def sizematcher(x): | 387 def sizematcher(expr): |
388 """Return a function(size) -> bool from the ``size()`` expression""" | 388 """Return a function(size) -> bool from the ``size()`` expression""" |
389 | 389 expr = expr.strip() |
390 # i18n: "size" is a keyword | |
391 expr = getstring(x, _("size requires an expression")).strip() | |
392 if '-' in expr: # do we have a range? | 390 if '-' in expr: # do we have a range? |
393 a, b = expr.split('-', 1) | 391 a, b = expr.split('-', 1) |
394 a = util.sizetoint(a) | 392 a = util.sizetoint(a) |
395 b = util.sizetoint(b) | 393 b = util.sizetoint(b) |
396 return lambda x: x >= a and x <= b | 394 return lambda x: x >= a and x <= b |
418 - size('1k') - files from 1024 to 2047 bytes | 416 - size('1k') - files from 1024 to 2047 bytes |
419 - size('< 20k') - files less than 20480 bytes | 417 - size('< 20k') - files less than 20480 bytes |
420 - size('>= .5MB') - files at least 524288 bytes | 418 - size('>= .5MB') - files at least 524288 bytes |
421 - size('4k - 1MB') - files from 4096 bytes to 1048576 bytes | 419 - size('4k - 1MB') - files from 4096 bytes to 1048576 bytes |
422 """ | 420 """ |
423 m = sizematcher(x) | 421 # i18n: "size" is a keyword |
422 expr = getstring(x, _("size requires an expression")) | |
423 m = sizematcher(expr) | |
424 return [f for f in mctx.existing() if m(mctx.ctx[f].size())] | 424 return [f for f in mctx.existing() if m(mctx.ctx[f].size())] |
425 | 425 |
426 @predicate('encoding(name)', callexisting=True) | 426 @predicate('encoding(name)', callexisting=True) |
427 def encoding(mctx, x): | 427 def encoding(mctx, x): |
428 """File can be successfully decoded with the given character | 428 """File can be successfully decoded with the given character |