Mercurial > public > mercurial-scm > hg-stable
comparison 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 |
comparison
equal
deleted
inserted
replaced
41574:66399f2e92aa | 41575:59638c6fcb70 |
---|---|
238 return x[1], None | 238 return x[1], None |
239 elif op == 'rangeall': | 239 elif op == 'rangeall': |
240 return None, None | 240 return None, None |
241 raise error.ParseError(err) | 241 raise error.ParseError(err) |
242 | 242 |
243 def getintrange(x, err1, err2, deffirst=_notset, deflast=_notset): | |
244 """Get [first, last] integer range (both inclusive) from a parsed tree | |
245 | |
246 If any of the sides omitted, and if no default provided, ParseError will | |
247 be raised. | |
248 """ | |
249 a, b = getrange(x, err1) | |
250 return getinteger(a, err2, deffirst), getinteger(b, err2, deflast) | |
251 | |
243 def getargs(x, min, max, err): | 252 def getargs(x, min, max, err): |
244 l = getlist(x) | 253 l = getlist(x) |
245 if len(l) < min or (max >= 0 and len(l) > max): | 254 if len(l) < min or (max >= 0 and len(l) > max): |
246 raise error.ParseError(err) | 255 raise error.ParseError(err) |
247 return l | 256 return l |