##// END OF EJS Templates
revset: factor out getinteger() helper...
Yuya Nishihara -
r30801:67ee7874 default
parent child Browse files
Show More
@@ -312,6 +312,12 b' def getstring(x, err):'
312 312 return x[1]
313 313 raise error.ParseError(err)
314 314
315 def getinteger(x, err):
316 try:
317 return int(getstring(x, err))
318 except ValueError:
319 raise error.ParseError(err)
320
315 321 def getlist(x):
316 322 if not x:
317 323 return []
@@ -539,10 +545,7 b' def ancestorspec(repo, subset, x, n, ord'
539 545 Changesets that are the Nth ancestor (first parents only) of a changeset
540 546 in set.
541 547 """
542 try:
543 n = int(n[1])
544 except (TypeError, ValueError):
545 raise error.ParseError(_("~ expects a number"))
548 n = getinteger(n, _("~ expects a number"))
546 549 ps = set()
547 550 cl = repo.changelog
548 551 for r in getset(repo, fullreposet(repo), x):
@@ -1098,10 +1101,8 b' def followlines(repo, subset, x):'
1098 1101 raise error.ParseError(_("followlines expects exactly one file"))
1099 1102 fname = files[0]
1100 1103
1101 try:
1102 fromline, toline = [int(getsymbol(a)) for a in args['lines']]
1103 except ValueError:
1104 raise error.ParseError(_("line range bounds must be integers"))
1104 fromline, toline = [getinteger(a, _("line range bounds must be integers"))
1105 for a in args['lines']]
1105 1106 if toline - fromline < 0:
1106 1107 raise error.ParseError(_("line range must be positive"))
1107 1108 if fromline < 1:
@@ -1273,19 +1274,15 b' def limit(repo, subset, x):'
1273 1274 if 'set' not in args:
1274 1275 # i18n: "limit" is a keyword
1275 1276 raise error.ParseError(_("limit requires one to three arguments"))
1276 try:
1277 lim, ofs = 1, 0
1278 if 'n' in args:
1279 # i18n: "limit" is a keyword
1280 lim = int(getstring(args['n'], _("limit requires a number")))
1281 if 'offset' in args:
1282 # i18n: "limit" is a keyword
1283 ofs = int(getstring(args['offset'], _("limit requires a number")))
1284 if ofs < 0:
1285 raise error.ParseError(_("negative offset"))
1286 except (TypeError, ValueError):
1277 lim, ofs = 1, 0
1278 if 'n' in args:
1287 1279 # i18n: "limit" is a keyword
1288 raise error.ParseError(_("limit expects a number"))
1280 lim = getinteger(args['n'], _("limit expects a number"))
1281 if 'offset' in args:
1282 # i18n: "limit" is a keyword
1283 ofs = getinteger(args['offset'], _("limit expects a number"))
1284 if ofs < 0:
1285 raise error.ParseError(_("negative offset"))
1289 1286 os = getset(repo, fullreposet(repo), args['set'])
1290 1287 result = []
1291 1288 it = iter(os)
@@ -1308,14 +1305,10 b' def last(repo, subset, x):'
1308 1305 """
1309 1306 # i18n: "last" is a keyword
1310 1307 l = getargs(x, 1, 2, _("last requires one or two arguments"))
1311 try:
1312 lim = 1
1313 if len(l) == 2:
1314 # i18n: "last" is a keyword
1315 lim = int(getstring(l[1], _("last requires a number")))
1316 except (TypeError, ValueError):
1308 lim = 1
1309 if len(l) == 2:
1317 1310 # i18n: "last" is a keyword
1318 raise error.ParseError(_("last expects a number"))
1311 lim = getinteger(l[1], _("last expects a number"))
1319 1312 os = getset(repo, fullreposet(repo), l[0])
1320 1313 os.reverse()
1321 1314 result = []
General Comments 0
You need to be logged in to leave comments. Login now