# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2018-02-26 19:03:46 # Node ID e2b87e19c6efa87f12da17350207ea6d97062cfd # Parent 1e1c1bfb0be452e5f33c6e802ed6798a027bdc62 pycompat: prevent encoding or decoding values if not required 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. Differential Revision: https://phab.mercurial-scm.org/D2472 diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py --- a/mercurial/pycompat.py +++ b/mercurial/pycompat.py @@ -192,11 +192,15 @@ if ispy3: def strurl(url): """Converts a bytes url back to str""" - return url.decode(u'ascii') + if isinstance(url, bytes): + return url.decode(u'ascii') + return url 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') + return url def raisewithtb(exc, tb): """Raise exception with the given traceback"""