pycompat: fix crash when default locale is unknown
Instead, fall back to the filesystem encoding if the default locale is unknown.
--- a/mercurial/pycompat.py Mon Jun 22 22:15:57 2020 -0700
+++ b/mercurial/pycompat.py Wed Jun 24 04:25:34 2020 +0200
@@ -178,9 +178,16 @@
if os.name == r'nt':
sysargv = [a.encode("mbcs", "ignore") for a in sys.argv]
else:
+
+ def getdefaultlocale_if_known():
+ try:
+ return locale.getdefaultlocale()
+ except ValueError:
+ return None, None
+
encoding = (
locale.getlocale()[1]
- or locale.getdefaultlocale()[1]
+ or getdefaultlocale_if_known()[1]
or sys.getfilesystemencoding()
)
sysargv = [a.encode(encoding, "surrogateescape") for a in sys.argv]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-locale.t Wed Jun 24 04:25:34 2020 +0200
@@ -0,0 +1,2 @@
+ $ LANG=nonexistent LC_ALL=nonexistent LANGUAGE=nonexistent hg version -q
+ Mercurial Distributed SCM (version *) (glob)