comparison mercurial/pycompat.py @ 43432:8d5489b048b7

py3: enable legacy fs encoding to fix filename compatibility on Windows This patch is untested. I just followed the instruction: https://docs.python.org/3/whatsnew/3.6.html#pep-529-change-windows-filesystem-encoding-to-utf-8
author Yuya Nishihara <yuya@tcha.org>
date Tue, 15 Oct 2019 22:44:55 +0900
parents 8ff1ecfadcd1
children 93f74a7d3f07
comparison
equal deleted inserted replaced
43431:21a1b2094649 43432:8d5489b048b7
89 if ispy3: 89 if ispy3:
90 import builtins 90 import builtins
91 import functools 91 import functools
92 import io 92 import io
93 import struct 93 import struct
94
95 if os.name == r'nt' and sys.version_info >= (3, 6):
96 # MBCS (or ANSI) filesystem encoding must be used as before.
97 # Otherwise non-ASCII filenames in existing repositories would be
98 # corrupted.
99 # This must be set once prior to any fsencode/fsdecode calls.
100 sys._enablelegacywindowsfsencoding()
94 101
95 fsencode = os.fsencode 102 fsencode = os.fsencode
96 fsdecode = os.fsdecode 103 fsdecode = os.fsdecode
97 oscurdir = os.curdir.encode('ascii') 104 oscurdir = os.curdir.encode('ascii')
98 oslinesep = os.linesep.encode('ascii') 105 oslinesep = os.linesep.encode('ascii')
135 # Since Python 3 converts argv to wchar_t type by Py_DecodeLocale() on Unix, 142 # Since Python 3 converts argv to wchar_t type by Py_DecodeLocale() on Unix,
136 # we can use os.fsencode() to get back bytes argv. 143 # we can use os.fsencode() to get back bytes argv.
137 # 144 #
138 # https://hg.python.org/cpython/file/v3.5.1/Programs/python.c#l55 145 # https://hg.python.org/cpython/file/v3.5.1/Programs/python.c#l55
139 # 146 #
140 # TODO: On Windows, the native argv is wchar_t, so we'll need a different 147 # On Windows, the native argv is unicode and is converted to MBCS bytes
141 # workaround to simulate the Python 2 (i.e. ANSI Win32 API) behavior. 148 # since we do enable the legacy filesystem encoding.
142 if getattr(sys, 'argv', None) is not None: 149 if getattr(sys, 'argv', None) is not None:
143 sysargv = list(map(os.fsencode, sys.argv)) 150 sysargv = list(map(os.fsencode, sys.argv))
144 151
145 bytechr = struct.Struct(r'>B').pack 152 bytechr = struct.Struct(r'>B').pack
146 byterepr = b'%r'.__mod__ 153 byterepr = b'%r'.__mod__