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

Augie Fackler raf at durin42.com
Tue Feb 5 09:13:10 EST 2019


queued, thanks

> On Feb 1, 2019, at 08:35, Yuya Nishihara <yuya at tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1548563857 -32400
> #      Sun Jan 27 13:37:37 2019 +0900
> # Node ID 84a273ff0d5254604d1f9d05d2dbdcebaadb5006
> # Parent  28b6a15f5bb2fcfa809532e27cf9008aa4f93d0d
> 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.
> 
> 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
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list