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

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 31, 2019, 2:19 p.m.
Message ID <4e7cb9965efc79214274.1548944360@mimosa>
Download mbox | patch
Permalink /patch/38256/
State Superseded
Headers show

Comments

Yuya Nishihara - Jan. 31, 2019, 2:19 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1548563857 -32400
#      Sun Jan 27 13:37:37 2019 +0900
# Node ID 4e7cb9965efc7921427418742ff2ca23f180b707
# Parent  d5978ebfee5ac4ec9694c8d1a2df37c7e1555bd3
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.
Anton Shestakov - Jan. 31, 2019, 3:25 p.m.
On Thu, 31 Jan 2019 23:19:20 +0900
Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1548563857 -32400
> #      Sun Jan 27 13:37:37 2019 +0900
> # Node ID 4e7cb9965efc7921427418742ff2ca23f180b707
> # Parent  d5978ebfee5ac4ec9694c8d1a2df37c7e1555bd3
> 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.
> 
> --- a/tests/test-revset.t
> +++ b/tests/test-revset.t
> @@ -643,13 +643,13 @@ 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 range
>    [255]

This doesn't feel right: it can totally be just one integer. I mean,
internally it's converted to range, but as a message to user the new
phrasing is less helpful.

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,12 @@  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 range'),
+                       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 +285,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,13 +643,13 @@  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 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 range
   [255]
   $ hg debugrevspec '.#generations[foo:bar]'
-  hg: parse error: relation subscript bounds must be integers
+  hg: parse error: relation subscript must be an integer range
   [255]
 
 suggested relations