diff mercurial/revsetlang.py @ 41575:59638c6fcb70

revset: extract a helper to parse integer range It's getting common. As a first step, this patch adds getintrange() and makes followlines() use it. I wanted to unify the error messages to make the function interface simple, but I failed to phrase it briefly.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 27 Jan 2019 13:18:53 +0900
parents b1ea90613af3
children 1c04894e8fe1
line wrap: on
line diff
--- a/mercurial/revsetlang.py	Thu Jan 31 14:47:34 2019 -0800
+++ b/mercurial/revsetlang.py	Sun Jan 27 13:18:53 2019 +0900
@@ -240,6 +240,15 @@
         return None, None
     raise error.ParseError(err)
 
+def getintrange(x, err1, err2, deffirst=_notset, deflast=_notset):
+    """Get [first, last] integer range (both inclusive) from a parsed tree
+
+    If any of the sides omitted, and if no default provided, ParseError will
+    be raised.
+    """
+    a, b = getrange(x, err1)
+    return getinteger(a, err2, deffirst), getinteger(b, err2, deflast)
+
 def getargs(x, min, max, err):
     l = getlist(x)
     if len(l) < min or (max >= 0 and len(l) > max):