Patchwork [1,of,2] revset: stabilise repr of baseset initialised with a set

login
register
mail settings
Submitter Pierre-Yves David
Date April 5, 2016, 1:13 a.m.
Message ID <0f39406de1cb1a95008c.1459818796@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/14361/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Pierre-Yves David - April 5, 2016, 1:13 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1459817115 25200
#      Mon Apr 04 17:45:15 2016 -0700
# Node ID 0f39406de1cb1a95008c3b97273ebc7da7bf7c6b
# Parent  4ea482ff4804dab641e23ad8d44c08db2b957d24
# Available At http://mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull http://mercurial-scm.org/repo/users/marmoute/mercurial/ -r 0f39406de1cb
# EXP-Topic pypy.revset
revset: stabilise repr of baseset initialised with a set

Cpython and pypy have different way to build and order set, so the result of
list(myset) is different. We work around this by using the sorted version of the
data when displaying a list.

This get pypy closer to pass test-revset.t.
Yuya Nishihara - April 5, 2016, 1:23 p.m.
On Mon, 04 Apr 2016 18:13:16 -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1459817115 25200
> #      Mon Apr 04 17:45:15 2016 -0700
> # Node ID 0f39406de1cb1a95008c3b97273ebc7da7bf7c6b
> # Parent  4ea482ff4804dab641e23ad8d44c08db2b957d24
> # Available At http://mercurial-scm.org/repo/users/marmoute/mercurial/
> #              hg pull http://mercurial-scm.org/repo/users/marmoute/mercurial/ -r 0f39406de1cb
> # EXP-Topic pypy.revset
> revset: stabilise repr of baseset initialised with a set

The series looks good to me, queued, thanks.

> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -2891,11 +2891,17 @@ class baseset(abstractsmartset):
>  
>      def __repr__(self):
>          d = {None: '', False: '-', True: '+'}[self._ascending]
>          s = _formatsetrepr(self._datarepr)
>          if not s:
> -            s = repr(self._list)
> +            l = self._list
> +            # if _list have been built from a set, it might have a different
> +            # order from one python implementation to another.
> +            # We fallback to the sorted version for a stable output.
> +            if self._ascending is not None:
> +                l = self._asclist

It could be implemented as a datarepr, but I have no preference.

             if isinstance(data, set):
                 self._set = data
             data = list(data)
+            if datarepr is None:
+                datarepr = lambda: repr(sorted(data))
         self._list = data
         self._datarepr = datarepr
         self._ascending = None

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2891,11 +2891,17 @@  class baseset(abstractsmartset):
 
     def __repr__(self):
         d = {None: '', False: '-', True: '+'}[self._ascending]
         s = _formatsetrepr(self._datarepr)
         if not s:
-            s = repr(self._list)
+            l = self._list
+            # if _list have been built from a set, it might have a different
+            # order from one python implementation to another.
+            # We fallback to the sorted version for a stable output.
+            if self._ascending is not None:
+                l = self._asclist
+            s = repr(l)
         return '<%s%s %s>' % (type(self).__name__, d, s)
 
 class filteredset(abstractsmartset):
     """Duck type for baseset class which iterates lazily over the revisions in
     the subset and contains a function which tests for membership in the
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -723,11 +723,11 @@  Test opreand of '%' is optimized recursi
     ('symbol', 'only')
     (list
       ('symbol', '9')
       ('symbol', '5')))
   * set:
-  <baseset+ [8, 9, 2, 4]>
+  <baseset+ [2, 4, 8, 9]>
   2
   4
   8
   9