changeset 14061:611d2f8a4ba2

revsets: add a last function last(set, n) = reverser(limit(reverse(set), n))
author Matt Mackall <mpm@selenic.com>
date Sat, 30 Apr 2011 10:56:43 -0500
parents aaa9a5989405
children 643381286e0c
files mercurial/revset.py
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Sat Apr 30 14:22:03 2011 +0200
+++ b/mercurial/revset.py	Sat Apr 30 10:56:43 2011 -0500
@@ -452,6 +452,20 @@
         raise error.ParseError(_("limit expects a number"))
     return getset(repo, subset, l[0])[:lim]
 
+def last(repo, subset, x):
+    """``last(set, n)``
+    Last n members of set.
+    """
+    # i18n: "last" is a keyword
+    l = getargs(x, 2, 2, _("last requires two arguments"))
+    try:
+        # i18n: "last" is a keyword
+        lim = int(getstring(l[1], _("last requires a number")))
+    except ValueError:
+        # i18n: "last" is a keyword
+        raise error.ParseError(_("last expects a number"))
+    return getset(repo, subset, l[0])[-lim:]
+
 def maxrev(repo, subset, x):
     """``max(set)``
     Changeset with highest revision number in set.
@@ -724,6 +738,7 @@
     "head": head,
     "heads": heads,
     "keyword": keyword,
+    "last": last,
     "limit": limit,
     "max": maxrev,
     "min": minrev,