Commits

Martijn Pieters committed b7b3064

Inline the issue6202 fix (posix version) instead of monkey-patching

  • Participants
  • Parent commits f91d32f

Comments (0)

Files changed (1)

File pending/getpreferredencoding.patch

 # HG changeset patch
 # Parent d59a623cc4c931af084b8696cc6ed896d583701e
 # User Martijn Pieters <mj@zopatista.com>
-# Date 1281728933 -7200
+# 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,16 +10,35 @@
+@@ -10,18 +10,30 @@
  
  _encodingfixup = {'646': 'ascii', 'ANSI_X3.4-1968': 'ascii'}
  
-+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 :-(
-+        def getpreferredencoding(do_setlocale = True):
-+            """Return the charset that the user is likely using,
-+            by looking at environment variables."""
++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:
-+        def getpreferredencoding(do_setlocale = True):
-+            """Return the charset that the user is likely using,
-+            according to the system configuration."""
-+            if do_setlocale:
-+                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.nl_langinfo(locale.CODESET)
-+    locale.getpreferredencoding = getpreferredencoding
++        return locale.getpreferredencoding()
 +
  try:
      encoding = os.environ.get("HGENCODING")
 -            locale.setlocale(locale.LC_CTYPE, 'en_US.UTF-8')
 -        encoding = locale.getlocale()[1]
      if not encoding:
-         encoding = locale.getpreferredencoding() or 'ascii'
+-        encoding = locale.getpreferredencoding() or 'ascii'
++        encoding = _preferredencoding() or 'ascii'
          encoding = _encodingfixup.get(encoding, encoding)
+ except locale.Error:
+     encoding = 'ascii'