merge with stable
authorAugie Fackler <augie@google.com>
Mon, 17 Jun 2019 13:21:41 -0400
changeset 42481 7a9e038d38a2
parent 42479 ed9a99564051 (current diff)
parent 42480 b6387a65851d (diff)
child 42482 cc4db4478467
merge with stable
--- a/mercurial/utils/cborutil.py	Fri Jun 14 00:30:33 2019 -0400
+++ b/mercurial/utils/cborutil.py	Mon Jun 17 13:21:41 2019 -0400
@@ -214,6 +214,14 @@
     fn = STREAM_ENCODERS.get(v.__class__)
 
     if not fn:
+        # handle subtypes such as encoding.localstr and util.sortdict
+        for ty in STREAM_ENCODERS:
+            if not isinstance(v, ty):
+                continue
+            fn = STREAM_ENCODERS[ty]
+            break
+
+    if not fn:
         raise ValueError('do not know how to encode %s' % type(v))
 
     return fn(v)
--- a/tests/test-template-functions.t	Fri Jun 14 00:30:33 2019 -0400
+++ b/tests/test-template-functions.t	Mon Jun 17 13:21:41 2019 -0400
@@ -1562,6 +1562,20 @@
   $ HGENCODING=ascii hg log -T "{'`cat latin1`'|json}\n" -l1
   "\udce9"
 
+cbor filter is bytes transparent, which should handle bytes subtypes
+as bytes:
+
+  $ HGENCODING=ascii hg log -T "{branch|cbor}" -r0 \
+  > | "$PYTHON" "$TESTTMP/decodecbor.py"
+  [
+   '?'
+  ]
+  $ HGENCODING=latin-1 hg log -T "{branch|cbor}" -r0 \
+  > | "$PYTHON" "$TESTTMP/decodecbor.py"
+  [
+   '\xe9'
+  ]
+
 utf8 filter:
 
   $ HGENCODING=ascii hg log -T "round-trip: {branch|utf8|hex}\n" -r0