[PATCH 3 of 5 V2] revset: use getargsdict for sort()

Martijn Pieters mj at zopatista.com
Tue May 24 01:12:00 EDT 2016


# HG changeset patch
# User Martijn Pieters <mjpieters at fb.com>
# Date 1464037790 25200
#      Mon May 23 14:09:50 2016 -0700
# Node ID 33021f61f93f4342f79528e61fa330ba47acbd4e
# Parent  eae833e8ed17f2da948155849daa2959ce535c38
revset: use getargsdict for sort()

This makes it possible to use keyword arguments to specify per-sort options.
For example, a hypothetical 'first' option for the user sort could sort certain
users first with:

    sort(all(), user, user.first=mpm at selenic.com)

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1847,14 +1847,16 @@
     - ``user`` for user name (``author`` can be used as an alias),
     - ``date`` for the commit date
     """
-    # i18n: "sort" is a keyword
-    l = getargs(x, 1, 2, _("sort requires one or two arguments"))
+    args = getargsdict(x, 'sort', 'set keys')
+    if 'set' not in args:
+        # i18n: "sort" is a keyword
+        raise error.ParseError(_('sort requires one or two arguments'))
     keys = "rev"
-    if len(l) == 2:
+    if 'keys' in args:
         # i18n: "sort" is a keyword
-        keys = getstring(l[1], _("sort spec must be a string"))
-
-    s = l[0]
+        keys = getstring(args['keys'], _("sort spec must be a string"))
+
+    s = args['set']
     keys = keys.split()
     revs = getset(repo, subset, s)
     if keys == ["rev"]:


More information about the Mercurial-devel mailing list