revset: use getintrange() to parse relation subscript
authorAnton Shestakov <av6@dwimlabs.net>
Wed, 06 Feb 2019 13:49:29 +0800
changeset 4390 312b9e8a4c9c
parent 4389 88887b2be07c
child 4391 054ff759f2fd
revset: use getintrange() to parse relation subscript After 13f7a6a4f0db parsing the tokens into usable values needs to happen inside subscript relation functions.
hgext3rd/topic/revset.py
--- a/hgext3rd/topic/revset.py	Sun Feb 03 12:04:50 2019 +0100
+++ b/hgext3rd/topic/revset.py	Wed Feb 06 13:49:29 2019 +0800
@@ -108,7 +108,7 @@
     return revset.baseset(stack.stack(repo, branch=branch, topic=topic)[1:]) & subset
 
 if util.safehasattr(revset, 'subscriptrelations'):
-    def stackrel(repo, subset, x, rel, a, *args):
+    def stackrel(repo, subset, x, rel, z, order):
         """This is a revset-flavored implementation of stack aliases.
 
         The syntax is: rev#stack[n] or rev#s[n]. Plenty of logic is borrowed
@@ -116,11 +116,15 @@
         (e.g. when stack index is too high), this returns empty set to be more
         revset-friendly.
         """
-        # hg 4.9 provides one bound, hg 5.0 provides two
-        if len(args) == 2:
-            b = args[0]
+        # hg 4.9 provides a number or None, hg 5.0 provides a tuple of tokens
+        if isinstance(z, tuple):
+            a, b = revset.getintrange(
+                z,
+                'relation subscript must be an integer or a range',
+                'relation subscript bounds must be integers',
+                None, None)
         else:
-            b = a
+            a = b = z
 
         s = revset.getset(repo, revset.fullreposet(repo), x)
         if not s: