Patchwork [2,of,4,V2] revset: comment that we can't swap 'or' operands by weight

login
register
mail settings
Submitter Yuya Nishihara
Date May 27, 2015, 3:14 p.m.
Message ID <a8e85b25edc7f73b2819.1432739663@mimosa>
Download mbox | patch
Permalink /patch/9295/
State Accepted
Headers show

Comments

Yuya Nishihara - May 27, 2015, 3:14 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1430040452 -32400
#      Sun Apr 26 18:27:32 2015 +0900
# Node ID a8e85b25edc7f73b28199eecfb92a8dee5507b73
# Parent  ba1e7a39338b162c2f36f8a2a6be05a9c80fdde6
revset: comment that we can't swap 'or' operands by weight

Though the original code did nothing, it tried to optimize the calculation
order by weight. But we can't simply swap 'ta' and 'tb' because it would
change the order of revisions.

For future reference, this patch keeps the modified version of the original
code as comment.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2162,8 +2162,10 @@  def optimize(x, small):
     elif op == 'or':
         wa, ta = optimize(x[1], False)
         wb, tb = optimize(x[2], False)
-        if wb < wa:
-            wb, wa = wa, wb
+        # we can't reorder trees by weight because it would change the order.
+        # ("sort(a + b)" == "sort(b + a)", but "a + b" != "b + a")
+        #   if wb < wa:
+        #       tb, ta = ta, tb
         return max(wa, wb), (op, ta, tb)
     elif op == 'not':
         # Optimize not public() to _notpublic() because we have a fast version