[PATCH] revset: add default error messages to getintrange()

Anton Shestakov av6 at dwimlabs.net
Wed Feb 6 06:39:54 UTC 2019


# HG changeset patch
# User Anton Shestakov <av6 at 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.

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):


More information about the Mercurial-devel mailing list