changeset 28253:c407583cf5f6 stable

log: fix order of revisions filtered by multiple OR options (issue5100) This is the simplest workaround for the issue of the ordering of revset, which is that the expression "x or y" takes over the ordering specified by the input set (or the left-hand-side expression.) For example, the following expression A & (x | y) will be evaluated as if (A & x) | (A & y) That's wrong because revset has ordering. I'm going to fix this problem in the revset module, but that wouldn't fit to stable. So, this patch just works around the common log cases. Since this change might have some impact on performance, it is enabled only if the expression built from log options has ' or ' operation.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 15 Feb 2016 22:46:07 +0900
parents f5b2b358b8b7
children 5f95d6a70e9b
files mercurial/cmdutil.py tests/test-log.t
diffstat 2 files changed, 116 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Thu Feb 25 22:35:11 2016 -0800
+++ b/mercurial/cmdutil.py	Mon Feb 15 22:46:07 2016 +0900
@@ -2139,9 +2139,15 @@
         # Revset matches can reorder revisions. "A or B" typically returns
         # returns the revision matching A then the revision matching B. Sort
         # again to fix that.
+        fixopts = ['branch', 'only_branch', 'keyword', 'user']
+        oldrevs = revs
         revs = matcher(repo, revs)
         if not opts.get('rev'):
             revs.sort(reverse=True)
+        elif len(pats) > 1 or any(len(opts.get(op, [])) > 1 for op in fixopts):
+            # XXX "A or B" is known to change the order; fix it by filtering
+            # matched set again (issue5100)
+            revs = oldrevs & revs
     if limit is not None:
         limitedrevs = []
         for idx, r in enumerate(revs):
--- a/tests/test-log.t	Thu Feb 25 22:35:11 2016 -0800
+++ b/tests/test-log.t	Mon Feb 15 22:46:07 2016 +0900
@@ -920,6 +920,116 @@
 
   $ cd ..
 
+Test that log should respect the order of -rREV even if multiple OR conditions
+are specified (issue5100):
+
+  $ hg init revorder
+  $ cd revorder
+
+  $ hg branch -q b0
+  $ echo 0 >> f0
+  $ hg ci -qAm k0 -u u0
+  $ hg branch -q b1
+  $ echo 1 >> f1
+  $ hg ci -qAm k1 -u u1
+  $ hg branch -q b2
+  $ echo 2 >> f2
+  $ hg ci -qAm k2 -u u2
+
+  $ hg update -q b2
+  $ echo 3 >> f2
+  $ hg ci -qAm k2 -u u2
+  $ hg update -q b1
+  $ echo 4 >> f1
+  $ hg ci -qAm k1 -u u1
+  $ hg update -q b0
+  $ echo 5 >> f0
+  $ hg ci -qAm k0 -u u0
+
+ summary of revisions:
+
+  $ hg log -G -T '{rev} {branch} {author} {desc} {files}\n'
+  @  5 b0 u0 k0 f0
+  |
+  | o  4 b1 u1 k1 f1
+  | |
+  | | o  3 b2 u2 k2 f2
+  | | |
+  | | o  2 b2 u2 k2 f2
+  | |/
+  | o  1 b1 u1 k1 f1
+  |/
+  o  0 b0 u0 k0 f0
+  
+
+ log -b BRANCH in ascending order:
+
+  $ hg log -r0:tip -T '{rev} {branch}\n' -b b0 -b b1
+  0 b0
+  1 b1
+  4 b1
+  5 b0
+  $ hg log -r0:tip -T '{rev} {branch}\n' -b b1 -b b0
+  0 b0
+  1 b1
+  4 b1
+  5 b0
+
+ log --only-branch BRANCH in descending order:
+
+  $ hg log -rtip:0 -T '{rev} {branch}\n' --only-branch b1 --only-branch b2
+  4 b1
+  3 b2
+  2 b2
+  1 b1
+  $ hg log -rtip:0 -T '{rev} {branch}\n' --only-branch b2 --only-branch b1
+  4 b1
+  3 b2
+  2 b2
+  1 b1
+
+ log -u USER in ascending order, against compound set:
+
+  $ hg log -r'::head()' -T '{rev} {author}\n' -u u0 -u u2
+  0 u0
+  2 u2
+  3 u2
+  5 u0
+  $ hg log -r'::head()' -T '{rev} {author}\n' -u u2 -u u0
+  0 u0
+  2 u2
+  3 u2
+  5 u0
+
+ log -k TEXT in descending order, against compound set:
+
+  $ hg log -r'5 + reverse(::3)' -T '{rev} {desc}\n' -k k0 -k k1 -k k2
+  5 k0
+  3 k2
+  2 k2
+  1 k1
+  0 k0
+  $ hg log -r'5 + reverse(::3)' -T '{rev} {desc}\n' -k k2 -k k1 -k k0
+  5 k0
+  3 k2
+  2 k2
+  1 k1
+  0 k0
+
+ log FILE in ascending order, against dagrange:
+
+  $ hg log -r1:: -T '{rev} {files}\n' f1 f2
+  1 f1
+  2 f2
+  3 f2
+  4 f1
+  $ hg log -r1:: -T '{rev} {files}\n' f2 f1
+  1 f1
+  2 f2
+  3 f2
+  4 f1
+
+  $ cd ..
 
 User