# HG changeset patch # User Augie Fackler # Date 2019-06-17 17:21:41 # Node ID 7a9e038d38a2fd59a5043e498205778ddb001788 # Parent ed9a995640518fd7fa893817f0250f4d319a4b40 # Parent b6387a65851d4421d5580b1a4db4c55366a94ec8 merge with stable diff --git a/mercurial/utils/cborutil.py b/mercurial/utils/cborutil.py --- a/mercurial/utils/cborutil.py +++ b/mercurial/utils/cborutil.py @@ -214,6 +214,14 @@ def streamencode(v): 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) diff --git a/tests/test-template-functions.t b/tests/test-template-functions.t --- a/tests/test-template-functions.t +++ b/tests/test-template-functions.t @@ -1562,6 +1562,20 @@ json filter takes input as utf-8b: $ 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