changeset 29365:f652e84f23f2

revset: extract function that validates sort() arguments This function will be used in _optimize() to get rid of noop sort() call while validating its arguments.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 11 Jun 2016 10:17:49 +0900
parents 76a1a703e23d
children d269e7db2f55
files mercurial/revset.py
diffstat 1 files changed, 24 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Wed Jun 15 21:26:45 2016 +0900
+++ b/mercurial/revset.py	Sat Jun 11 10:17:49 2016 +0900
@@ -1843,25 +1843,8 @@
     'date': lambda c: c.date()[0],
 }
 
-@predicate('sort(set[, [-]key... [, ...]])', safe=True)
-def sort(repo, subset, x):
-    """Sort set by keys. The default sort order is ascending, specify a key
-    as ``-key`` to sort in descending order.
-
-    The keys can be:
-
-    - ``rev`` for the revision number,
-    - ``branch`` for the branch name,
-    - ``desc`` for the commit message (description),
-    - ``user`` for user name (``author`` can be used as an alias),
-    - ``date`` for the commit date
-    - ``topo`` for a reverse topographical sort
-
-    The ``topo`` sort order cannot be combined with other sort keys. This sort
-    takes one optional argument, ``topo.firstbranch``, which takes a revset that
-    specifies what topographical branches to prioritize in the sort.
-
-    """
+def _getsortargs(x):
+    """Parse sort options into (set, [(key, reverse)], opts)"""
     args = getargsdict(x, 'sort', 'set keys topo.firstbranch')
     if 'set' not in args:
         # i18n: "sort" is a keyword
@@ -1896,7 +1879,28 @@
                 'topo.firstbranch can only be used when using the topo sort '
                 'key'))
 
-    s = args['set']
+    return args['set'], keyflags, opts
+
+@predicate('sort(set[, [-]key... [, ...]])', safe=True)
+def sort(repo, subset, x):
+    """Sort set by keys. The default sort order is ascending, specify a key
+    as ``-key`` to sort in descending order.
+
+    The keys can be:
+
+    - ``rev`` for the revision number,
+    - ``branch`` for the branch name,
+    - ``desc`` for the commit message (description),
+    - ``user`` for user name (``author`` can be used as an alias),
+    - ``date`` for the commit date
+    - ``topo`` for a reverse topographical sort
+
+    The ``topo`` sort order cannot be combined with other sort keys. This sort
+    takes one optional argument, ``topo.firstbranch``, which takes a revset that
+    specifies what topographical branches to prioritize in the sort.
+
+    """
+    s, keyflags, opts = _getsortargs(x)
     revs = getset(repo, subset, s)
 
     if not keyflags: