revset: leverage getintrange() helper in relation-subscript operation (API)
authorYuya Nishihara <yuya@tcha.org>
Sun, 27 Jan 2019 13:37:37 +0900
changeset 41563 13f7a6a4f0db
parent 41562 1c04894e8fe1
child 41564 a5493a251ad3
revset: leverage getintrange() helper in relation-subscript operation (API) Now a range expression is parsed by a relation function itself since the upper layer have no knowledge about the default first/last bounds.
mercurial/revset.py
tests/test-revset.t
--- a/mercurial/revset.py	Sun Jan 27 13:28:45 2019 +0900
+++ b/mercurial/revset.py	Sun Jan 27 13:37:37 2019 +0900
@@ -43,7 +43,6 @@
 getinteger = revsetlang.getinteger
 getboolean = revsetlang.getboolean
 getlist = revsetlang.getlist
-getrange = revsetlang.getrange
 getintrange = revsetlang.getintrange
 getargs = revsetlang.getargs
 getargsdict = revsetlang.getargsdict
@@ -256,14 +255,14 @@
         descdepths = (max(a, 0), b + 1)
     return ancdepths, descdepths
 
-def generationsrel(repo, subset, x, rel, a, b, order):
+def generationsrel(repo, subset, x, rel, z, order):
     # TODO: rewrite tests, and drop startdepth argument from ancestors() and
     # descendants() predicates
-    if a is None:
-        a = -(dagop.maxlogdepth - 1)
-    if b is None:
-        b = +(dagop.maxlogdepth - 1)
-
+    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)
 
     if ancstart is None and descstart is None:
@@ -288,21 +287,8 @@
     # experimental so undocumented. see the wiki for further ideas.
     # https://www.mercurial-scm.org/wiki/RevsetOperatorPlan
     rel = getsymbol(y)
-    try:
-        a, b = getrange(z, '')
-    except error.ParseError:
-        a = getinteger(z, _("relation subscript must be an integer"))
-        b = a
-    else:
-        def getbound(i):
-            if i is None:
-                return None
-            msg = _("relation subscript bounds must be integers")
-            return getinteger(i, msg)
-        a, b = [getbound(i) for i in (a, b)]
-
     if rel in subscriptrelations:
-        return subscriptrelations[rel](repo, subset, x, rel, a, b, order)
+        return subscriptrelations[rel](repo, subset, x, rel, z, order)
 
     relnames = [r for r in subscriptrelations.keys() if len(r) > 1]
     raise error.UnknownIdentifier(rel, relnames)
--- a/tests/test-revset.t	Sun Jan 27 13:28:45 2019 +0900
+++ b/tests/test-revset.t	Sun Jan 27 13:37:37 2019 +0900
@@ -643,10 +643,10 @@
   [255]
 
   $ hg debugrevspec '.#generations[a]'
-  hg: parse error: relation subscript must be an integer
+  hg: parse error: relation subscript must be an integer or a range
   [255]
   $ hg debugrevspec '.#generations[1-2]'
-  hg: parse error: relation subscript must be an integer
+  hg: parse error: relation subscript must be an integer or a range
   [255]
   $ hg debugrevspec '.#generations[foo:bar]'
   hg: parse error: relation subscript bounds must be integers