Patchwork [4,of,4] revset: make sort() noop depending on ordering requirement (BC)

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 14, 2016, 4:40 p.m.
Message ID <062fc2b7adb13fc714c8.1473871240@mimosa>
Download mbox | patch
Permalink /patch/16626/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 14, 2016, 4:40 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1462250172 -32400
#      Tue May 03 13:36:12 2016 +0900
# Node ID 062fc2b7adb13fc714c897e9fa5edc02b77555d4
# Parent  849cc143ef7a4a95813f91618db6353018939c46
revset: make sort() noop depending on ordering requirement (BC)

See the previous patch for why.
Pierre-Yves David - Sept. 16, 2016, 12:17 p.m.
On 09/14/2016 06:40 PM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1462250172 -32400
> #      Tue May 03 13:36:12 2016 +0900
> # Node ID 062fc2b7adb13fc714c897e9fa5edc02b77555d4
> # Parent  849cc143ef7a4a95813f91618db6353018939c46
> revset: make sort() noop depending on ordering requirement (BC)
>
> See the previous patch for why.

Pushed, thanks.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1901,8 +1901,8 @@  def _getsortargs(x):
 
     return args['set'], keyflags, opts
 
-@predicate('sort(set[, [-]key... [, ...]])', safe=True)
-def sort(repo, subset, x):
+@predicate('sort(set[, [-]key... [, ...]])', safe=True, takeorder=True)
+def sort(repo, subset, x, order):
     """Sort set by keys. The default sort order is ascending, specify a key
     as ``-key`` to sort in descending order.
 
@@ -1923,7 +1923,7 @@  def sort(repo, subset, x):
     s, keyflags, opts = _getsortargs(x)
     revs = getset(repo, subset, s)
 
-    if not keyflags:
+    if not keyflags or order != defineorder:
         return revs
     if len(keyflags) == 1 and keyflags[0][0] == "rev":
         revs.sort(reverse=keyflags[0][1])
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1633,12 +1633,20 @@  ordering defined by it.
     define)
   * set:
   <filteredset
-    <spanset- 0:2>,
+    <spanset+ 0:2>,
     <spanset+ 0:9>>
+  0
+  1
   2
-  1
-  0
- BROKEN: should be '0 1 2'
+
+ invalid argument passed to noop sort():
+
+  $ log '0:2 & sort()'
+  hg: parse error: sort requires one or two arguments
+  [255]
+  $ log '0:2 & sort(all(), -invalid)'
+  hg: parse error: unknown sort key '-invalid'
+  [255]
 
  for 'A & f(B)', 'B' should not be affected by the order of 'A':