# HG changeset patch # User Yuya Nishihara # Date 2017-03-12 23:26:34 # Node ID 2e48c776a874b3154aff3dbf6de06faacacf81a0 # Parent 52ee1b5ac277bd5569a8d3e3ae3e11dff0543323 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. diff --git a/mercurial/lock.py b/mercurial/lock.py --- a/mercurial/lock.py +++ b/mercurial/lock.py @@ -28,8 +28,9 @@ def _getlockprefix(): 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