# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 2018-03-03 03:47:18
# Node ID c98d1c6763a6ece66ff135eb8b2b03cc2ce71e13
# Parent  70415568ea65a22c06f0c2a3cca8717e883e4325

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

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -702,6 +702,9 @@ DATA_ESCAPE_MAP.update({
 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):