[PATCH 3 of 4] revset: build dict of extra sort options before evaluating set

Yuya Nishihara yuya at tcha.org
Wed Jun 15 09:42:54 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1465993605 -32400
#      Wed Jun 15 21:26:45 2016 +0900
# Node ID daaf43a9a70c5b62652b864b6c2f440ac58a2215
# Parent  29d03589403b37677ae254f51476e07805b23d62
revset: build dict of extra sort options before evaluating set

Prepares for extracting a function that only validates sort options.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1881,30 +1881,33 @@ def sort(repo, subset, x):
             raise error.ParseError(_("unknown sort key %r") % fk)
         keyflags.append((k, reverse))
 
-    s = args['set']
-    revs = getset(repo, subset, s)
-
     if len(keyflags) > 1 and any(k == 'topo' for k, reverse in keyflags):
         # i18n: "topo" is a keyword
         raise error.ParseError(_(
             'topo sort order cannot be combined with other sort keys'))
 
-    firstbranch = ()
+    opts = {}
     if 'topo.firstbranch' in args:
         if any(k == 'topo' for k, reverse in keyflags):
-            firstbranch = getset(repo, subset, args['topo.firstbranch'])
+            opts['topo.firstbranch'] = args['topo.firstbranch']
         else:
             # i18n: "topo" and "topo.firstbranch" are keywords
             raise error.ParseError(_(
                 'topo.firstbranch can only be used when using the topo sort '
                 'key'))
 
+    s = args['set']
+    revs = getset(repo, subset, s)
+
     if not keyflags:
         return revs
     if len(keyflags) == 1 and keyflags[0][0] == "rev":
         revs.sort(reverse=keyflags[0][1])
         return revs
     elif keyflags[0][0] == "topo":
+        firstbranch = ()
+        if 'topo.firstbranch' in opts:
+            firstbranch = getset(repo, subset, opts['topo.firstbranch'])
         revs = baseset(_toposort(revs, repo.changelog.parentrevs, firstbranch),
                        istopo=True)
         if keyflags[0][1]:


More information about the Mercurial-devel mailing list