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: + , + >, + >> + 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: , - > + , + > + 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: , - > + , + > 1 'A & B' can be rewritten as 'B & A' by weight, but that's fine as long as