Patchwork [2,of,4] revset: fix order of nested 'range' expression (BC)

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

Comments

Yuya Nishihara - Sept. 14, 2016, 4:40 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1462247570 -32400
#      Tue May 03 12:52:50 2016 +0900
# Node ID 7054518fb85e9ec814c5946528bcc8ceacae7460
# Parent  95c25bf44c2361b0148f7f2d7e0db2070e959594
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."

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -378,12 +378,12 @@  def rangeset(repo, subset, x, y, order):
         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)
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1255,6 +1255,36 @@  ordering defined by it.
   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 @@  ordering defined by it.
     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 @@  ordering defined by it.
     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