util: teach escapedata() about bytearray
authorGregory Szorc <gregory.szorc@gmail.com>
Fri, 02 Mar 2018 22:47:18 -0500
changeset 36629 c98d1c6763a6
parent 36628 70415568ea65
child 36630 29128309c52d
util: teach escapedata() about bytearray re.map doesn't seem to know about bytearray (at least in Python 2). Cast bytearray to a bytes to work around this inconvenience. Differential Revision: https://phab.mercurial-scm.org/D2582
mercurial/util.py
--- a/mercurial/util.py	Fri Mar 02 22:59:12 2018 -0500
+++ b/mercurial/util.py	Fri Mar 02 22:47:18 2018 -0500
@@ -702,6 +702,9 @@
 DATA_ESCAPE_RE = remod.compile(br'[\x00-\x08\x0a-\x1f\\\x7f-\xff]')
 
 def escapedata(s):
+    if isinstance(s, bytearray):
+        s = bytes(s)
+
     return DATA_ESCAPE_RE.sub(lambda m: DATA_ESCAPE_MAP[m.group(0)], s)
 
 class fileobjectobserver(object):