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

login
register
mail settings
Submitter Anton Shestakov
Date Aug. 8, 2015, 6:45 a.m.
Message ID <549f62ce99ce03403594.1439016308@neuro>
Download mbox | patch
Permalink /patch/10163/
State Accepted
Headers show

Comments

Anton Shestakov - Aug. 8, 2015, 6:45 a.m.
# HG changeset patch
# User Anton Shestakov <av6@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.
Yuya Nishihara - Aug. 9, 2015, 8:59 a.m.
On Sat, 08 Aug 2015 14:45:08 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6@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.
Pierre-Yves David - Aug. 10, 2015, 5:47 a.m.
On 08/09/2015 01:59 AM, Yuya Nishihara wrote:
> On Sat, 08 Aug 2015 14:45:08 +0800, Anton Shestakov wrote:
>> # HG changeset patch
>> # User Anton Shestakov <av6@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.

Thanks for digging the stable eligibility.

I've pushed this to the clowncopter.

Patch

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")'
+  $ fileset 'size("1 GB")'
 
 Test merge states