Patchwork revset: add default error messages to getintrange()

login
register
mail settings
Submitter Anton Shestakov
Date Feb. 6, 2019, 6:39 a.m.
Message ID <e87cf73bbbffd69efa77.1549435194@neuro>
Download mbox | patch
Permalink /patch/38474/
State New
Headers show

Comments

Anton Shestakov - Feb. 6, 2019, 6:39 a.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1549432950 -28800
#      Wed Feb 06 14:02:30 2019 +0800
# Node ID e87cf73bbbffd69efa77b93fa4190d8e0987f339
# Parent  a5493a251ad3a724b0a7a1bff21248c39611c6de
revset: add default error messages to getintrange()

Looks like it's the default values that will vary from one subscript relation
function to another, but the currently used error messages work for most cases
(the function is called "getintrange", after all). Let's make it possible to
reuse these messages.
Yuya Nishihara - Feb. 6, 2019, 12:15 p.m.
On Wed, 06 Feb 2019 14:39:54 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6@dwimlabs.net>
> # Date 1549432950 -28800
> #      Wed Feb 06 14:02:30 2019 +0800
> # Node ID e87cf73bbbffd69efa77b93fa4190d8e0987f339
> # Parent  a5493a251ad3a724b0a7a1bff21248c39611c6de
> revset: add default error messages to getintrange()
> 
> Looks like it's the default values that will vary from one subscript relation
> function to another, but the currently used error messages work for most cases
> (the function is called "getintrange", after all). Let's make it possible to
> reuse these messages.

> -def getintrange(x, err1, err2, deffirst=_notset, deflast=_notset):
> +def getintrange(x, err1=None, err2=None, deffirst=_notset, deflast=_notset):
>      """Get [first, last] integer range (both inclusive) from a parsed tree
>  
>      If any of the sides omitted, and if no default provided, ParseError will
>      be raised.
>      """
> +    if err1 is None:
> +        err1 = _('relation subscript must be an integer or a range')
>      if x and (x[0] == 'string' or x[0] == 'symbol'):
>          n = getinteger(x, err1)
>          return n, n
>      a, b = getrange(x, err1)
> +    if err2 is None:
> +        err2 = _('relation subscript bounds must be integers'),

We'll have to remove "relation subscript" from the default message because
it is the function for parsing arbitrary range values.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -259,8 +259,6 @@  def generationsrel(repo, subset, x, rel,
     # TODO: rewrite tests, and drop startdepth argument from ancestors() and
     # descendants() predicates
     a, b = getintrange(z,
-                       _('relation subscript must be an integer or a range'),
-                       _('relation subscript bounds must be integers'),
                        deffirst=-(dagop.maxlogdepth - 1),
                        deflast=+(dagop.maxlogdepth - 1))
     (ancstart, ancstop), (descstart, descstop) = _splitrange(a, b)
diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py
--- a/mercurial/revsetlang.py
+++ b/mercurial/revsetlang.py
@@ -240,16 +240,20 @@  def getrange(x, err):
         return None, None
     raise error.ParseError(err)
 
-def getintrange(x, err1, err2, deffirst=_notset, deflast=_notset):
+def getintrange(x, err1=None, err2=None, deffirst=_notset, deflast=_notset):
     """Get [first, last] integer range (both inclusive) from a parsed tree
 
     If any of the sides omitted, and if no default provided, ParseError will
     be raised.
     """
+    if err1 is None:
+        err1 = _('relation subscript must be an integer or a range')
     if x and (x[0] == 'string' or x[0] == 'symbol'):
         n = getinteger(x, err1)
         return n, n
     a, b = getrange(x, err1)
+    if err2 is None:
+        err2 = _('relation subscript bounds must be integers'),
     return getinteger(a, err2, deffirst), getinteger(b, err2, deflast)
 
 def getargs(x, min, max, err):