Patchwork D3504: cborutil: port to Python 3

login
register
mail settings
Submitter phabricator
Date May 8, 2018, 8:22 p.m.
Message ID <13073b0d9599d491685f6c8c46d0da75@localhost.localdomain>
Download mbox | patch
Permalink /patch/31412/
State Not Applicable
Headers show

Comments

phabricator - May 8, 2018, 8:22 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG2ae6a3134362: cborutil: port to Python 3 (authored by durin42, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3504?vs=8572&id=8580

REVISION DETAIL
  https://phab.mercurial-scm.org/D3504

AFFECTED FILES
  mercurial/utils/cborutil.py

CHANGE DETAILS




To: durin42, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel

Patch

diff --git a/mercurial/utils/cborutil.py b/mercurial/utils/cborutil.py
--- a/mercurial/utils/cborutil.py
+++ b/mercurial/utils/cborutil.py
@@ -140,12 +140,15 @@ 
 
     yield BREAK
 
+def _mixedtypesortkey(v):
+    return type(v).__name__, v
+
 def streamencodeset(s):
     # https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml defines
     # semantic tag 258 for finite sets.
     yield encodelength(MAJOR_TYPE_SEMANTIC, 258)
 
-    for chunk in streamencodearray(sorted(s)):
+    for chunk in streamencodearray(sorted(s, key=_mixedtypesortkey)):
         yield chunk
 
 def streamencodemap(d):
@@ -155,7 +158,8 @@ 
     """
     yield encodelength(MAJOR_TYPE_MAP, len(d))
 
-    for key, value in sorted(d.iteritems()):
+    for key, value in sorted(d.iteritems(),
+                             key=lambda x: _mixedtypesortkey(x[0])):
         for chunk in streamencode(key):
             yield chunk
         for chunk in streamencode(value):