changeset 29944:5f56a3b9675e

revset: fix order of nested 'range' expression (BC) Enforce range order only if necessary as the comment says "carrying the sorting over would be more efficient."
author Yuya Nishihara <yuya@tcha.org>
date Tue, 03 May 2016 12:52:50 +0900
parents 80c86b9bb40b
children 89dbae952ec1
files mercurial/revset.py tests/test-revset.t
diffstat 2 files changed, 41 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Wed Jun 01 20:54:04 2016 +0900
+++ b/mercurial/revset.py	Tue May 03 12:52:50 2016 +0900
@@ -378,12 +378,12 @@
         r = spanset(repo, m, n + 1)
     else:
         r = spanset(repo, m, n - 1)
-    # XXX We should combine with subset first: 'subset & baseset(...)'. This is
-    # necessary to ensure we preserve the order in subset.
-    #
-    # This has performance implication, carrying the sorting over when possible
-    # would be more efficient.
-    return r & subset
+
+    if order == defineorder:
+        return r & subset
+    else:
+        # carrying the sorting over when possible would be more efficient
+        return subset & r
 
 def dagrange(repo, subset, x, y, order):
     r = fullreposet(repo)
--- a/tests/test-revset.t	Wed Jun 01 20:54:04 2016 +0900
+++ b/tests/test-revset.t	Tue May 03 12:52:50 2016 +0900
@@ -1255,6 +1255,36 @@
   1
   0
 
+ 'x:y' takes ordering parameter into account:
+
+  $ try -p optimized '3:0 & 0:3 & not 2:1'
+  * optimized:
+  (difference
+    (and
+      (range
+        ('symbol', '3')
+        ('symbol', '0')
+        define)
+      (range
+        ('symbol', '0')
+        ('symbol', '3')
+        follow)
+      define)
+    (range
+      ('symbol', '2')
+      ('symbol', '1')
+      any)
+    define)
+  * set:
+  <filteredset
+    <filteredset
+      <spanset- 0:3>,
+      <spanset+ 0:3>>,
+    <not
+      <spanset+ 1:2>>>
+  3
+  0
+
  'a + b', which is optimized to '_list(a b)', should take the ordering of
  the left expression:
 
@@ -1377,12 +1407,11 @@
     define)
   * set:
   <filteredset
-    <spanset- 0:2>,
-    <baseset [0, 2, 1]>>
+    <baseset [0, 2, 1]>,
+    <spanset- 0:2>>
+  0
   2
   1
-  0
- BROKEN: should be '0 2 1'
 
  '_hexlist(a b)' should behave like 'a + b':
 
@@ -1724,8 +1753,8 @@
     define)
   * set:
   <filteredset
-    <baseset [1]>,
-    <spanset- 0:2>>
+    <spanset- 0:2>,
+    <baseset [1]>>
   1
 
  'A & B' can be rewritten as 'B & A' by weight, but that's fine as long as