[PATCH STABLE] filesets: ignore unit case in size() predicate for single value

Yuya Nishihara yuya at tcha.org
Sun Aug 9 03:59:02 CDT 2015


On Sat, 08 Aug 2015 14:45:08 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6 at dwimlabs.net>
> # Date 1439016147 -28800
> #      Sat Aug 08 14:42:27 2015 +0800
> # Branch stable
> # Node ID 549f62ce99ce034035943334e9608ba8e74823ce
> # Parent  f64f5adf2e364fecd106a3a3e68012c01a33c108
> filesets: ignore unit case in size() predicate for single value
> 
> When specifying one plain value in size(), e.g. size(1k), fileset tries to
> guess the upper bound automatically (see the comment in _sizetomax()). It
> didn't ignore the specified unit's case, and so size("1 GB"), for example,
> produced this error:
> 
> hg: parse error: couldn't parse size: 1 GB
> 
> Let's do the same thing that util.sizetoint() does: .lower().
> 
> The two test lines without output just check that there are no parse errors.
> 
> diff --git a/mercurial/fileset.py b/mercurial/fileset.py
> --- a/mercurial/fileset.py
> +++ b/mercurial/fileset.py
> @@ -287,7 +287,7 @@ def grep(mctx, x):
>  
>  def _sizetomax(s):
>      try:
> -        s = s.strip()
> +        s = s.strip().lower()
>          for k, v in util._sizeunits:
>              if s.endswith(k):
>                  # max(4k) = 5k - 1, max(4.5k) = 4.6k - 1
> diff --git a/tests/test-fileset.t b/tests/test-fileset.t
> --- a/tests/test-fileset.t
> +++ b/tests/test-fileset.t
> @@ -144,6 +144,8 @@ Test files properties
>    2k
>    $ fileset '(1k or 2k) and size(".5KB - 1.5kB")'
>    1k
> +  $ fileset 'size("1M")'

LGTM for stable because size("<1M") is already allowed.


More information about the Mercurial-devel mailing list