# HG changeset patch # User Brendan Cully # Date 1181589271 25200 # Node ID 133a52d70958824380aa31985402de5e66b976d4 # Parent e6c69a2491ed97d94b1d666e23f64ecf2f917fe4 Respect locale environment variables on darwin. In python 2.4+ on darwin, locale.getpreferredencoding() returns mac-roman regardless of what LC_CTYPE, LANG etc are set to. This can produce hard-to-notice conversion errors if input text is not in mac-roman. So this patch overrides it with setlocale/getlocale if the environment has been customized, on the assumption that the user has done so deliberately. diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -17,8 +17,15 @@ import cStringIO, errno, getpass, popen2 import os, threading, time, calendar, ConfigParser, locale, glob try: - _encoding = os.environ.get("HGENCODING") or locale.getpreferredencoding() \ - or "ascii" + _encoding = os.environ.get("HGENCODING") + if sys.platform == 'darwin' and not _encoding: + # On darwin, getpreferredencoding ignores the locale environment and + # always returns mac-roman. We override this if the environment is + # not C (has been customized by the user). + locale.setlocale(locale.LC_CTYPE, '') + _encoding = locale.getlocale()[1] + if not _encoding: + _encoding = locale.getpreferredencoding() or 'ascii' except locale.Error: _encoding = 'ascii' _encodingmode = os.environ.get("HGENCODINGMODE", "strict")