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

login
register
mail settings
Submitter Yuya Nishihara
Date June 15, 2016, 1:42 p.m.
Message ID <daaf43a9a70c5b62652b.1465998174@mimosa>
Download mbox | patch
Permalink /patch/15516/
State Accepted
Headers show

Comments

Yuya Nishihara - June 15, 2016, 1:42 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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.

Patch

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]: