# HG changeset patch # User Mads Kiilerich # Date 1537647634 -7200 # Node ID 0e33880b289721cf35d26f516533336d34a9f0bb # Parent 6bd262eaa058e189760fda42bf282f01b9ef0a11 config: abort early if the environment doesn't allow Python to pass Unicode strings to the file system layer Dulwich passes unicode paths to the file system layer and it will thus not work if run with LC_ALL=C ... which is quite common for services. Also try to detect different cases and give helpful error messages about what environment variable could be changed to what. diff -r 6bd262eaa058 -r 0e33880b2897 kallithea/config/app_cfg.py --- a/kallithea/config/app_cfg.py Tue Sep 18 20:57:32 2018 +0200 +++ b/kallithea/config/app_cfg.py Sat Sep 22 22:20:34 2018 +0200 @@ -120,6 +120,22 @@ def setup_configuration(app): config = app.config + # Verify that things work when Dulwich passes unicode paths to the file system layer. + # Note: UTF-8 is preferred, but for example ISO-8859-1 or mbcs should also work under the right cirumstances. + try: + u'\xe9'.encode(sys.getfilesystemencoding()) # Test using é (é) + except UnicodeEncodeError: + log.error("Cannot encode Unicode paths to file system encoding %r", sys.getfilesystemencoding()) + for var in ['LC_CTYPE', 'LC_ALL', 'LANG']: + if var in os.environ: + val = os.environ[var] + log.error("Note: Environment variable %s is %r - perhaps change it to some other value from 'locale -a', like 'C.UTF-8' or 'en_US.UTF-8'", var, val) + break + else: + log.error("Note: No locale setting found in environment variables - perhaps set LC_CTYPE to some value from 'locale -a', like 'C.UTF-8' or 'en_US.UTF-8'") + log.error("Terminating ...") + sys.exit(1) + # Mercurial sets encoding at module import time, so we have to monkey patch it hgencoding = config.get('hgencoding') if hgencoding: