mercurial/revset.py
changeset 26638 7afaf2566e25
parent 26637 179764469754
child 26713 a271925699d6
equal deleted inserted replaced
26637:179764469754 26638:7afaf2566e25
  1282                    for t in c.files() + [c.user(), c.description()])
  1282                    for t in c.files() + [c.user(), c.description()])
  1283 
  1283 
  1284     return subset.filter(matches)
  1284     return subset.filter(matches)
  1285 
  1285 
  1286 def limit(repo, subset, x):
  1286 def limit(repo, subset, x):
  1287     """``limit(set, [n])``
  1287     """``limit(set[, n[, offset]])``
  1288     First n members of set, defaulting to 1.
  1288     First n members of set, defaulting to 1, starting from offset.
  1289     """
  1289     """
  1290     args = getargsdict(x, 'limit', 'set n')
  1290     args = getargsdict(x, 'limit', 'set n offset')
  1291     if 'set' not in args:
  1291     if 'set' not in args:
  1292         # i18n: "limit" is a keyword
  1292         # i18n: "limit" is a keyword
  1293         raise error.ParseError(_("limit requires one or two arguments"))
  1293         raise error.ParseError(_("limit requires one to three arguments"))
  1294     try:
  1294     try:
  1295         lim = 1
  1295         lim, ofs = 1, 0
  1296         if 'n' in args:
  1296         if 'n' in args:
  1297             # i18n: "limit" is a keyword
  1297             # i18n: "limit" is a keyword
  1298             lim = int(getstring(args['n'], _("limit requires a number")))
  1298             lim = int(getstring(args['n'], _("limit requires a number")))
       
  1299         if 'offset' in args:
       
  1300             # i18n: "limit" is a keyword
       
  1301             ofs = int(getstring(args['offset'], _("limit requires a number")))
       
  1302         if ofs < 0:
       
  1303             raise error.ParseError(_("negative offset"))
  1299     except (TypeError, ValueError):
  1304     except (TypeError, ValueError):
  1300         # i18n: "limit" is a keyword
  1305         # i18n: "limit" is a keyword
  1301         raise error.ParseError(_("limit expects a number"))
  1306         raise error.ParseError(_("limit expects a number"))
  1302     os = getset(repo, fullreposet(repo), args['set'])
  1307     os = getset(repo, fullreposet(repo), args['set'])
  1303     result = []
  1308     result = []
  1304     it = iter(os)
  1309     it = iter(os)
       
  1310     for x in xrange(ofs):
       
  1311         y = next(it, None)
       
  1312         if y is None:
       
  1313             break
  1305     for x in xrange(lim):
  1314     for x in xrange(lim):
  1306         y = next(it, None)
  1315         y = next(it, None)
  1307         if y is None:
  1316         if y is None:
  1308             break
  1317             break
  1309         elif y in subset:
  1318         elif y in subset: