Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revset.py @ 15116:d8501bcbb221
revset: add default of 1 to limit and last functions
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 16 Sep 2011 22:57:47 -0500 |
parents | a773119f30ba |
children | 0ab1c3a1f3b2 |
comparison
equal
deleted
inserted
replaced
15115:c84b3f42d5ae | 15116:d8501bcbb221 |
---|---|
511 if kw in t.lower(): | 511 if kw in t.lower(): |
512 l.append(r) | 512 l.append(r) |
513 return l | 513 return l |
514 | 514 |
515 def limit(repo, subset, x): | 515 def limit(repo, subset, x): |
516 """``limit(set, n)`` | 516 """``limit(set, [n])`` |
517 First n members of set. | 517 First n members of set, defaulting to 1. |
518 """ | 518 """ |
519 # i18n: "limit" is a keyword | 519 # i18n: "limit" is a keyword |
520 l = getargs(x, 2, 2, _("limit requires two arguments")) | 520 l = getargs(x, 1, 2, _("limit requires one or two arguments")) |
521 try: | 521 try: |
522 # i18n: "limit" is a keyword | 522 lim = 1 |
523 lim = int(getstring(l[1], _("limit requires a number"))) | 523 if len(l) == 2: |
524 # i18n: "limit" is a keyword | |
525 lim = int(getstring(l[1], _("limit requires a number"))) | |
524 except (TypeError, ValueError): | 526 except (TypeError, ValueError): |
525 # i18n: "limit" is a keyword | 527 # i18n: "limit" is a keyword |
526 raise error.ParseError(_("limit expects a number")) | 528 raise error.ParseError(_("limit expects a number")) |
527 ss = set(subset) | 529 ss = set(subset) |
528 os = getset(repo, range(len(repo)), l[0])[:lim] | 530 os = getset(repo, range(len(repo)), l[0])[:lim] |
529 return [r for r in os if r in ss] | 531 return [r for r in os if r in ss] |
530 | 532 |
531 def last(repo, subset, x): | 533 def last(repo, subset, x): |
532 """``last(set, n)`` | 534 """``last(set, [n])`` |
533 Last n members of set. | 535 Last n members of set, defaulting to 1. |
534 """ | 536 """ |
535 # i18n: "last" is a keyword | 537 # i18n: "last" is a keyword |
536 l = getargs(x, 2, 2, _("last requires two arguments")) | 538 l = getargs(x, 1, 2, _("last requires one or two arguments")) |
537 try: | 539 try: |
538 # i18n: "last" is a keyword | 540 lim = 1 |
539 lim = int(getstring(l[1], _("last requires a number"))) | 541 if len(l) == 2: |
542 # i18n: "last" is a keyword | |
543 lim = int(getstring(l[1], _("last requires a number"))) | |
540 except (TypeError, ValueError): | 544 except (TypeError, ValueError): |
541 # i18n: "last" is a keyword | 545 # i18n: "last" is a keyword |
542 raise error.ParseError(_("last expects a number")) | 546 raise error.ParseError(_("last expects a number")) |
543 ss = set(subset) | 547 ss = set(subset) |
544 os = getset(repo, range(len(repo)), l[0])[-lim:] | 548 os = getset(repo, range(len(repo)), l[0])[-lim:] |