D2472: pycompat: prevent encoding or decoding values if not required
pulkit (Pulkit Goyal)
phabricator at mercurial-scm.org
Tue Feb 27 09:36:40 UTC 2018
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
pycompat.py has functions strurl and bytesurl which decodes and encodes the url
passed on Python 3 respectively. In some cases, strurl gets a url which is
already str and bytesurl gets a url which is already bytes. Let's prevent
encoding or decoding the values again if not required.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D2472
AFFECTED FILES
mercurial/pycompat.py
CHANGE DETAILS
diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -192,11 +192,13 @@
def strurl(url):
"""Converts a bytes url back to str"""
- return url.decode(u'ascii')
+ if isinstance(url, bytes):
+ return url.decode(u'ascii')
def bytesurl(url):
"""Converts a str url to bytes by encoding in ascii"""
- return url.encode(u'ascii')
+ if isinstance(url, str):
+ return url.encode(u'ascii')
def raisewithtb(exc, tb):
"""Raise exception with the given traceback"""
To: pulkit, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list