Patchwork [V2] revset: fix sorting key of wdir revision

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 10, 2020, 2:02 a.m.
Message ID <1ffc832a5390d73e844f.1602295370@mimosa>
Download mbox | patch
Permalink /patch/47427/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 10, 2020, 2:02 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1602238750 -32400
#      Fri Oct 09 19:19:10 2020 +0900
# Node ID 1ffc832a5390d73e844ff7f6e4cc05b168030fe0
# Parent  17a12f53dd72d39ce62721a0a43b681d4b4b4bb8
revset: fix sorting key of wdir revision

It would go wrong on Python 2, and would crash on Python 3.
Pulkit Goyal - Oct. 13, 2020, 7:37 a.m.
On Sat, Oct 10, 2020 at 7:35 AM Yuya Nishihara <yuya@tcha.org> wrote:
>
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1602238750 -32400
> #      Fri Oct 09 19:19:10 2020 +0900
> # Node ID 1ffc832a5390d73e844ff7f6e4cc05b168030fe0
> # Parent  17a12f53dd72d39ce62721a0a43b681d4b4b4bb8
> revset: fix sorting key of wdir revision
>
> It would go wrong on Python 2, and would crash on Python 3.

Queued this, many thanks!

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2287,13 +2287,13 @@  def roots(repo, subset, x):
 
 
 _sortkeyfuncs = {
-    b'rev': lambda c: c.rev(),
+    b'rev': scmutil.intrev,
     b'branch': lambda c: c.branch(),
     b'desc': lambda c: c.description(),
     b'user': lambda c: c.user(),
     b'author': lambda c: c.user(),
     b'date': lambda c: c.date()[0],
-    b'node': lambda c: c.node(),
+    b'node': scmutil.binnode,
 }
 
 
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -2899,6 +2899,29 @@  test sorting by multiple keys including 
   0 b12  m111 u112 111 10800
   2 b111 m11  u12  111 3600
 
+ sort including wdir (rev/-rev has fast path):
+
+  $ hg log -r 'sort(. + wdir(), rev)' -T '{rev}\n'
+  4
+  2147483647
+  $ hg log -r 'sort(. + wdir(), -rev)' -T '{rev}\n'
+  2147483647
+  4
+
+  $ hg log -r 'sort(. + wdir(), "branch rev")' -T '{rev}\n'
+  4
+  2147483647
+  $ hg log -r 'sort(. + wdir(), "branch -rev")' -T '{rev}\n'
+  2147483647
+  4
+
+  $ hg log -r 'sort(. + wdir(), node)' -T '{node}\n'
+  ec7c1c90b589ade8603d5fb619dc6c25173a723f
+  ffffffffffffffffffffffffffffffffffffffff
+  $ hg log -r 'sort(. + wdir(), -node)' -T '{node}\n'
+  ffffffffffffffffffffffffffffffffffffffff
+  ec7c1c90b589ade8603d5fb619dc6c25173a723f
+
  toposort prioritises graph branches
 
   $ hg up 2