util: implement a deterministic __repr__ on sortdict
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 17 Jul 2016 15:10:30 -0700
changeset 29592 37cccad55410
parent 29591 6215b5537ba5
child 29593 953839de96ab
util: implement a deterministic __repr__ on sortdict `hg debugbundle` is calling repr() on bundle2 part params, which are now util.sortdict instances. Unfortunately, repr() doesn't appear to be deterministic for util.sortdict. So, we implement one. We include the type name because that's the common convention for __repr__ implementations. Having the type name in `hg debugbundle` is a bit ugly. But it's a debug command and I don't care enough to fix it.
mercurial/util.py
tests/test-bundle-type.t
tests/test-bundle2-format.t
tests/test-debugbundle.t
tests/test-generaldelta.t
tests/test-getbundle.t
tests/test-shelve.t
tests/test-strip.t
--- a/mercurial/util.py	Sun Jul 17 14:51:00 2016 -0700
+++ b/mercurial/util.py	Sun Jul 17 15:10:30 2016 -0700
@@ -527,6 +527,10 @@
     def insert(self, index, key, val):
         self._list.insert(index, key)
         dict.__setitem__(self, key, val)
+    def __repr__(self):
+        if not self:
+            return '%s()' % self.__class__.__name__
+        return '%s(%r)' % (self.__class__.__name__, self.items())
 
 class _lrucachenode(object):
     """A node in a doubly linked list.
--- a/tests/test-bundle-type.t	Sun Jul 17 14:51:00 2016 -0700
+++ b/tests/test-bundle-type.t	Sun Jul 17 15:10:30 2016 -0700
@@ -52,7 +52,7 @@
   1 changesets found
   HG20\x00\x00 (esc)
   Stream params: {}
-  changegroup -- "{'version': '02'}"
+  changegroup -- "sortdict([('version', '02')])"
       c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
   none-v2
   
@@ -60,8 +60,8 @@
   searching for changes
   1 changesets found
   HG20\x00\x00 (esc)
-  Stream params: {'Compression': 'BZ'}
-  changegroup -- "{'version': '02'}"
+  Stream params: sortdict([('Compression', 'BZ')])
+  changegroup -- "sortdict([('version', '02')])"
       c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
   bzip2-v2
   
@@ -69,8 +69,8 @@
   searching for changes
   1 changesets found
   HG20\x00\x00 (esc)
-  Stream params: {'Compression': 'GZ'}
-  changegroup -- "{'version': '02'}"
+  Stream params: sortdict([('Compression', 'GZ')])
+  changegroup -- "sortdict([('version', '02')])"
       c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
   gzip-v2
   
@@ -79,7 +79,7 @@
   1 changesets found
   HG20\x00\x00 (esc)
   Stream params: {}
-  changegroup -- "{'version': '02'}"
+  changegroup -- "sortdict([('version', '02')])"
       c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
   none-v2
   
@@ -87,8 +87,8 @@
   searching for changes
   1 changesets found
   HG20\x00\x00 (esc)
-  Stream params: {'Compression': 'BZ'}
-  changegroup -- "{'version': '02'}"
+  Stream params: sortdict([('Compression', 'BZ')])
+  changegroup -- "sortdict([('version', '02')])"
       c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
   bzip2-v2
   
--- a/tests/test-bundle2-format.t	Sun Jul 17 14:51:00 2016 -0700
+++ b/tests/test-bundle2-format.t	Sun Jul 17 15:10:30 2016 -0700
@@ -990,7 +990,7 @@
 
   $ hg debugbundle ../rev.hg2
   Stream params: {}
-  changegroup -- '{}'
+  changegroup -- 'sortdict()'
       32af7686d403cf45b5d95f2d70cebea587ac806a
       9520eea781bcca16c1e15acc0ba14335a0e8e5ba
       eea13746799a9e0bfd88f29d3c2e9dc9389f524f
@@ -1118,8 +1118,8 @@
   0360: db fb 6a 33 df c1 7d 99 cf ef d4 d5 6d da 77 7c |..j3..}.....m.w||
   0370: 3b 19 fd af c5 3f f1 60 c3 17                   |;....?.`..|
   $ hg debugbundle ../rev.hg2.bz
-  Stream params: {'Compression': 'GZ'}
-  changegroup -- '{}'
+  Stream params: sortdict([('Compression', 'GZ')])
+  changegroup -- 'sortdict()'
       32af7686d403cf45b5d95f2d70cebea587ac806a
       9520eea781bcca16c1e15acc0ba14335a0e8e5ba
       eea13746799a9e0bfd88f29d3c2e9dc9389f524f
@@ -1205,8 +1205,8 @@
   0420: 8b 43 88 57 9c 01 f5 61 b5 e1 27 41 7e af 83 fe |.C.W...a..'A~...|
   0430: 2e e4 8a 70 a1 21 46 96 30 7a                   |...p.!F.0z|
   $ hg debugbundle ../rev.hg2.bz
-  Stream params: {'Compression': 'BZ'}
-  changegroup -- '{}'
+  Stream params: sortdict([('Compression', 'BZ')])
+  changegroup -- 'sortdict()'
       32af7686d403cf45b5d95f2d70cebea587ac806a
       9520eea781bcca16c1e15acc0ba14335a0e8e5ba
       eea13746799a9e0bfd88f29d3c2e9dc9389f524f
--- a/tests/test-debugbundle.t	Sun Jul 17 14:51:00 2016 -0700
+++ b/tests/test-debugbundle.t	Sun Jul 17 15:10:30 2016 -0700
@@ -31,7 +31,7 @@
 
   $ hg debugbundle bundle2.hg
   Stream params: {}
-  changegroup -- "{'version': '02'}"
+  changegroup -- "sortdict([('version', '02')])"
       0e067c57feba1a5694ca4844f05588bb1bf82342
       991a3460af53952d10ec8a295d3d2cc2e5fa9690
 
@@ -56,7 +56,7 @@
 
   $ hg debugbundle --all bundle2.hg
   Stream params: {}
-  changegroup -- "{'version': '02'}"
+  changegroup -- "sortdict([('version', '02')])"
       format: id, p1, p2, cset, delta base, len(delta)
   
       changelog
--- a/tests/test-generaldelta.t	Sun Jul 17 14:51:00 2016 -0700
+++ b/tests/test-generaldelta.t	Sun Jul 17 15:10:30 2016 -0700
@@ -154,8 +154,8 @@
   0 files updated, 0 files merged, 5 files removed, 0 files unresolved
   saved backup bundle to $TESTTMP/aggressive/.hg/strip-backup/1c5d4dc9a8b8-6c68e60c-backup.hg (glob)
   $ hg debugbundle .hg/strip-backup/*
-  Stream params: {'Compression': 'BZ'}
-  changegroup -- "{'version': '02'}"
+  Stream params: sortdict([('Compression', 'BZ')])
+  changegroup -- "sortdict([('version', '02')])"
       1c5d4dc9a8b8d6e1750966d343e94db665e7a1e9
 
   $ cd ..
--- a/tests/test-getbundle.t	Sun Jul 17 14:51:00 2016 -0700
+++ b/tests/test-getbundle.t	Sun Jul 17 15:10:30 2016 -0700
@@ -170,7 +170,7 @@
   $ hg debuggetbundle repo bundle -t bundle2
   $ hg debugbundle bundle
   Stream params: {}
-  changegroup -- "{'version': '01'}"
+  changegroup -- "sortdict([('version', '01')])"
       7704483d56b2a7b5db54dcee7c62378ac629b348
       29a4d1f17bd3f0779ca0525bebb1cfb51067c738
       713346a995c363120712aed1aee7e04afd867638
--- a/tests/test-shelve.t	Sun Jul 17 14:51:00 2016 -0700
+++ b/tests/test-shelve.t	Sun Jul 17 15:10:30 2016 -0700
@@ -1044,8 +1044,8 @@
   shelved as default
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   $ hg debugbundle .hg/shelved/*.hg
-  Stream params: {'Compression': 'BZ'}
-  changegroup -- "{'version': '02'}"
+  Stream params: sortdict([('Compression', 'BZ')])
+  changegroup -- "sortdict([('version', '02')])"
       45993d65fe9dc3c6d8764b9c3b07fa831ee7d92d
   $ cd ..
 
--- a/tests/test-strip.t	Sun Jul 17 14:51:00 2016 -0700
+++ b/tests/test-strip.t	Sun Jul 17 15:10:30 2016 -0700
@@ -210,8 +210,8 @@
   summary:     b
   
   $ hg debugbundle .hg/strip-backup/*
-  Stream params: {'Compression': 'BZ'}
-  changegroup -- "{'version': '02'}"
+  Stream params: sortdict([('Compression', 'BZ')])
+  changegroup -- "sortdict([('version', '02')])"
       264128213d290d868c54642d13aeaa3675551a78
   $ hg pull .hg/strip-backup/*
   pulling from .hg/strip-backup/264128213d29-0b39d6bf-backup.hg