--- a/hgext/extdiff.py Mon Mar 13 09:24:53 2017 -0700
+++ b/hgext/extdiff.py Wed Mar 15 23:06:50 2017 +0900
@@ -342,7 +342,7 @@
def __init__(self, path, cmdline):
# We can't pass non-ASCII through docstrings (and path is
# in an unknown encoding anyway)
- docpath = path.encode("string-escape")
+ docpath = util.escapestr(path)
self.__doc__ = self.__doc__ % {'path': util.uirepr(docpath)}
self._cmdline = cmdline
--- a/mercurial/cmdutil.py Mon Mar 13 09:24:53 2017 -0700
+++ b/mercurial/cmdutil.py Wed Mar 15 23:06:50 2017 +0900
@@ -1300,7 +1300,7 @@
for key, value in sorted(extra.items()):
# i18n: column positioning for "hg log"
self.ui.write(_("extra: %s=%s\n")
- % (key, value.encode('string_escape')),
+ % (key, util.escapestr(value)),
label='ui.debug log.extra')
description = ctx.description().strip()
--- a/mercurial/debugcommands.py Mon Mar 13 09:24:53 2017 -0700
+++ b/mercurial/debugcommands.py Wed Mar 15 23:06:50 2017 +0900
@@ -1514,8 +1514,8 @@
return not r
else:
for k, v in sorted(target.listkeys(namespace).iteritems()):
- ui.write("%s\t%s\n" % (k.encode('string-escape'),
- v.encode('string-escape')))
+ ui.write("%s\t%s\n" % (util.escapestr(k),
+ util.escapestr(v)))
@command('debugpvec', [], _('A B'))
def debugpvec(ui, repo, a, b=None):
--- a/mercurial/subrepo.py Mon Mar 13 09:24:53 2017 -0700
+++ b/mercurial/subrepo.py Wed Mar 15 23:06:50 2017 +0900
@@ -130,7 +130,7 @@
for pattern, repl in p.items('subpaths'):
# Turn r'C:\foo\bar' into r'C:\\foo\\bar' since re.sub
# does a string decode.
- repl = repl.encode('string-escape')
+ repl = util.escapestr(repl)
# However, we still want to allow back references to go
# through unharmed, so we turn r'\\1' into r'\1'. Again,
# extra escapes are needed because re.sub string decodes.
--- a/mercurial/templatefilters.py Mon Mar 13 09:24:53 2017 -0700
+++ b/mercurial/templatefilters.py Wed Mar 15 23:06:50 2017 +0900
@@ -345,7 +345,7 @@
@templatefilter('stringescape')
def stringescape(text):
- return text.encode('string_escape')
+ return util.escapestr(text)
@templatefilter('stringify')
def stringify(thing):
--- a/mercurial/util.py Mon Mar 13 09:24:53 2017 -0700
+++ b/mercurial/util.py Wed Mar 15 23:06:50 2017 +0900
@@ -2130,6 +2130,9 @@
(1, 1, _('%.0f bytes')),
)
+def escapestr(s):
+ return s.encode('string_escape')
+
def uirepr(s):
# Avoid double backslash in Windows path repr()
return repr(s).replace('\\\\', '\\')
--- a/mercurial/wireproto.py Mon Mar 13 09:24:53 2017 -0700
+++ b/mercurial/wireproto.py Wed Mar 15 23:06:50 2017 +0900
@@ -900,7 +900,7 @@
def pushkey(repo, proto, namespace, key, old, new):
# compatibility with pre-1.8 clients which were accidentally
# sending raw binary nodes rather than utf-8-encoded hex
- if len(new) == 20 and new.encode('string-escape') != new:
+ if len(new) == 20 and util.escapestr(new) != new:
# looks like it could be a binary node
try:
new.decode('utf-8')