Patchwork [3,of,3,V2] revset: leverage getintrange() helper in relation-subscript operation (API)

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 1, 2019, 1:23 p.m.
Message ID <6bcce54288ec2833fc21.1549027418@mimosa>
Download mbox | patch
Permalink /patch/38290/
State Superseded
Headers show

Comments

Yuya Nishihara - Feb. 1, 2019, 1:23 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1548563857 -32400
#      Sun Jan 27 13:37:37 2019 +0900
# Node ID 6bcce54288ec2833fc2153b8ad3af1918a0eb7e5
# Parent  a72c5cfe7b8da68563a1fb07d1477a9804d28d74
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.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -43,7 +43,6 @@  getstring = revsetlang.getstring
 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 @@  def _splitrange(a, b):
         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 @@  def relsubscriptset(repo, subset, x, y, 
     # 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)
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -643,10 +643,10 @@  parse errors of relation, subscript and 
   [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