Patchwork fileset: drop bad "elif:" trying to check invalid size expression

login
register
mail settings
Submitter Yuya Nishihara
Date March 1, 2018, 10:15 a.m.
Message ID <a6867dc78e35bc2a988f.1519899355@mimosa>
Download mbox | patch
Permalink /patch/28542/
State Accepted
Headers show

Comments

Yuya Nishihara - March 1, 2018, 10:15 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1519897822 18000
#      Thu Mar 01 04:50:22 2018 -0500
# Node ID a6867dc78e35bc2a988f62668e59bc3610087821
# Parent  b8c2209d738009dcbbf1f7d9352ce0ad21448c04
fileset: drop bad "elif:" trying to check invalid size expression

Since str.isdigit is a function, the last "elif" was always true. An invalid
expression is rejected by util.sizetoint(), so we don't need "elif".
Pulkit Goyal - March 1, 2018, 12:53 p.m.
Looks good to me.

On Thu, Mar 1, 2018 at 3:45 PM, Yuya Nishihara <yuya@tcha.org> wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1519897822 18000
> #      Thu Mar 01 04:50:22 2018 -0500
> # Node ID a6867dc78e35bc2a988f62668e59bc3610087821
> # Parent  b8c2209d738009dcbbf1f7d9352ce0ad21448c04
> fileset: drop bad "elif:" trying to check invalid size expression
>
> Since str.isdigit is a function, the last "elif" was always true. An invalid
> expression is rejected by util.sizetoint(), so we don't need "elif".
>
> diff --git a/mercurial/fileset.py b/mercurial/fileset.py
> --- a/mercurial/fileset.py
> +++ b/mercurial/fileset.py
> @@ -392,11 +392,10 @@ def sizematcher(x):
>      elif expr.startswith(">"):
>          a = util.sizetoint(expr[1:])
>          return lambda x: x > a
> -    elif expr[0:1].isdigit or expr.startswith('.'):
> +    else:
>          a = util.sizetoint(expr)
>          b = _sizetomax(expr)
>          return lambda x: x >= a and x <= b
> -    raise error.ParseError(_("couldn't parse size: %s") % expr)
>
>  @predicate('size(expression)', callexisting=True)
>  def size(mctx, x):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Pulkit Goyal - March 1, 2018, 7:43 p.m.
On Thu, Mar 1, 2018 at 6:23 PM, Pulkit Goyal <7895pulkit@gmail.com> wrote:
> Looks good to me.

And queued too. Thanks.

Patch

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -392,11 +392,10 @@  def sizematcher(x):
     elif expr.startswith(">"):
         a = util.sizetoint(expr[1:])
         return lambda x: x > a
-    elif expr[0:1].isdigit or expr.startswith('.'):
+    else:
         a = util.sizetoint(expr)
         b = _sizetomax(expr)
         return lambda x: x >= a and x <= b
-    raise error.ParseError(_("couldn't parse size: %s") % expr)
 
 @predicate('size(expression)', callexisting=True)
 def size(mctx, x):