Patchwork [4,of,9] fileset: parse argument of size() by predicate function

login
register
mail settings
Submitter Yuya Nishihara
Date July 10, 2018, 3:07 p.m.
Message ID <5a3ee7bdeca33fc59996.1531235262@mimosa>
Download mbox | patch
Permalink /patch/32762/
State Accepted
Headers show

Comments

Yuya Nishihara - July 10, 2018, 3:07 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1528631890 -32400
#      Sun Jun 10 20:58:10 2018 +0900
# Node ID 5a3ee7bdeca33fc599967aab894f5219eb6ecaa4
# Parent  cd1f2f078f12e4a2ee4fb301161a7275e5098b21
fileset: parse argument of size() by predicate function

This change is necessary to pass in a size expression to predicatematcher.
See the next patch.

Patch

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -384,11 +384,9 @@  def _sizetomax(s):
     except ValueError:
         raise error.ParseError(_("couldn't parse size: %s") % s)
 
-def sizematcher(x):
+def sizematcher(expr):
     """Return a function(size) -> bool from the ``size()`` expression"""
-
-    # i18n: "size" is a keyword
-    expr = getstring(x, _("size requires an expression")).strip()
+    expr = expr.strip()
     if '-' in expr: # do we have a range?
         a, b = expr.split('-', 1)
         a = util.sizetoint(a)
@@ -420,7 +418,9 @@  def size(mctx, x):
     - size('>= .5MB') - files at least 524288 bytes
     - size('4k - 1MB') - files from 4096 bytes to 1048576 bytes
     """
-    m = sizematcher(x)
+    # i18n: "size" is a keyword
+    expr = getstring(x, _("size requires an expression"))
+    m = sizematcher(expr)
     return [f for f in mctx.existing() if m(mctx.ctx[f].size())]
 
 @predicate('encoding(name)', callexisting=True)
diff --git a/mercurial/minifileset.py b/mercurial/minifileset.py
--- a/mercurial/minifileset.py
+++ b/mercurial/minifileset.py
@@ -14,6 +14,11 @@  from . import (
     pycompat,
 )
 
+def _sizep(x):
+    # i18n: "size" is a keyword
+    expr = fileset.getstring(x, _("size requires an expression"))
+    return fileset.sizematcher(expr)
+
 def _compile(tree):
     if not tree:
         raise error.ParseError(_("missing argument"))
@@ -50,7 +55,7 @@  def _compile(tree):
         symbols = {
             'all': lambda n, s: True,
             'none': lambda n, s: False,
-            'size': lambda n, s: fileset.sizematcher(tree[2])(s),
+            'size': lambda n, s: _sizep(tree[2])(s),
         }
 
         name = fileset.getsymbol(tree[1])