Commits

Martijn Pieters committed 5259206
  • Participants
  • Parent commits b7b3064

Comments (0)

Files changed (1)

File pending/getpreferredencoding.patch

-# HG changeset patch
-# Parent d59a623cc4c931af084b8696cc6ed896d583701e
-# User Martijn Pieters <mj@zopatista.com>
-# Date 1281768624 -7200
-
-Use the POSIX version of getpreferredencoding on Mac, see http://bugs.python.org/issue6203
-
-diff --git a/mercurial/encoding.py b/mercurial/encoding.py
---- a/mercurial/encoding.py
-+++ b/mercurial/encoding.py
-@@ -10,18 +10,30 @@
- 
- _encodingfixup = {'646': 'ascii', 'ANSI_X3.4-1968': 'ascii'}
- 
-+def _preferredencoding():
-+    if sys.version_info[:2] < (2, 7) and sys.platform in ('darwin', 'mac'):
-+        # On darwin, getpreferredencoding ignores the locale environment and
-+        # always returns mac-roman. http://bugs.python.org/issue6202 fixes
-+        # this for Python 2.7 and up. This is the same corrected code for
-+        # earlier Python versions.
-+        try:
-+            locale.CODESET
-+        except AttributeError:
-+            # Fall back to parsing environment variables :-(
-+            return locale.getdefaultlocale()[1]
-+        else:
-+            oldloc = locale.setlocale(locale.LC_CTYPE)
-+            locale.setlocale(locale.LC_CTYPE, "")
-+            result = locale.nl_langinfo(locale.CODESET)
-+            locale.setlocale(locale.LC_CTYPE, oldloc)
-+            return result
-+    else:
-+        return locale.getpreferredencoding()
-+
- try:
-     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).
--        lc = locale.setlocale(locale.LC_CTYPE, '')
--        if lc == 'UTF-8':
--            locale.setlocale(locale.LC_CTYPE, 'en_US.UTF-8')
--        encoding = locale.getlocale()[1]
-     if not encoding:
--        encoding = locale.getpreferredencoding() or 'ascii'
-+        encoding = _preferredencoding() or 'ascii'
-         encoding = _encodingfixup.get(encoding, encoding)
- except locale.Error:
-     encoding = 'ascii'