revsets: add a last function
authorMatt Mackall <mpm@selenic.com>
Sat, 30 Apr 2011 10:56:43 -0500
changeset 14061 611d2f8a4ba2
parent 14060 aaa9a5989405
child 14062 643381286e0c
revsets: add a last function last(set, n) = reverser(limit(reverse(set), n))
mercurial/revset.py
--- 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,