changeset 31387:2e48c776a874

lock: do not encode result of gethostname on Python 2 If a hostname contained non-ascii character, str.encode() would first try to decode it to a unicode and raise UnicodeDecodeError.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 12 Mar 2017 16:26:34 -0700
parents 52ee1b5ac277
children b6a6df38a802
files mercurial/lock.py
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/lock.py	Sun Mar 12 03:33:38 2017 -0400
+++ b/mercurial/lock.py	Sun Mar 12 16:26:34 2017 -0700
@@ -28,8 +28,9 @@
     confidence. Typically it's just hostname. On modern linux, we include an
     extra Linux-specific pid namespace identifier.
     """
-    result = socket.gethostname().encode(
-        pycompat.sysstr(encoding.encoding), 'replace')
+    result = socket.gethostname()
+    if pycompat.ispy3:
+        result = result.encode(pycompat.sysstr(encoding.encoding), 'replace')
     if pycompat.sysplatform.startswith('linux'):
         try:
             result += '/%x' % os.stat('/proc/self/ns/pid').st_ino