Patchwork [2,of,2] revset: fix heads() order to always follow the input set (BC)

login
register
mail settings
Submitter Yuya Nishihara
Date June 27, 2018, 2:52 p.m.
Message ID <542ca250795430ee77ae.1530111152@mimosa>
Download mbox | patch
Permalink /patch/32465/
State Accepted
Headers show

Comments

Yuya Nishihara - June 27, 2018, 2:52 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1530110381 -32400
#      Wed Jun 27 23:39:41 2018 +0900
# Node ID 542ca250795430ee77aeb5e5558f36f60dab3ca1
# Parent  5aee640e2a99a305dc6f5219c35d2140180169a1
revset: fix heads() order to always follow the input set (BC)

An argument expression should never affect the order of the result set.
That's the rule of the revset predicates.
via Mercurial-devel - June 27, 2018, 3:23 p.m.
On Wed, Jun 27, 2018 at 7:53 AM Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1530110381 -32400
> #      Wed Jun 27 23:39:41 2018 +0900
> # Node ID 542ca250795430ee77aeb5e5558f36f60dab3ca1
> # Parent  5aee640e2a99a305dc6f5219c35d2140180169a1
> revset: fix heads() order to always follow the input set (BC)
>

Queuing this, thanks.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1129,11 +1129,14 @@  def head(repo, subset, x):
         hs.update(cl.rev(h) for h in ls)
     return subset & baseset(hs)
 
-@predicate('heads(set)', safe=True)
-def heads(repo, subset, x):
+@predicate('heads(set)', safe=True, takeorder=True)
+def heads(repo, subset, x, order):
     """Members of set with no children in set.
     """
-    s = getset(repo, subset, x)
+    # argument set should never define order
+    if order == defineorder:
+        order = followorder
+    s = getset(repo, subset, x, order=order)
     ps = parents(repo, subset, x)
     return s - ps
 
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1376,20 +1376,20 @@  Test heads
         <baseset [9]>, set([0, 1, 2, 3, 4, 5, 6, 8])>>>
   9
 
- BROKEN: but should follow the order of the subset
+ but should follow the order of the subset
 
   $ log 'heads(all())'
   7
   9
   $ log 'heads(tip:0)'
+  7
   9
-  7
   $ log 'tip:0 & heads(all())'
   9
   7
   $ log 'tip:0 & heads(0:tip)'
+  9
   7
-  9
 
   $ log 'keyword(issue)'
   6