[PATCH] work around broken locale on darwin (MacOS X)

Matt Mackall mpm at selenic.com
Fri Jan 12 10:00:43 CST 2007


On Fri, Jan 12, 2007 at 03:26:57PM +0100, Christian Ebert wrote:
> # HG changeset patch
> # User Christian Ebert <blacktrash at gmx.net>
> # Date 1168611810 -3600
> # Node ID f65f155be5c104d1a4a88660415c2305057fdfa7
> # Parent  6ea8a3b805ee5ce9794ca653e85c40ac86ec468d
> work around broken locale on darwin (MacOS X)
> 
> diff -r 6ea8a3b805ee -r f65f155be5c1 contrib/convert-repo
> --- a/contrib/convert-repo	Wed Jan 10 20:35:27 2007 +0100
> +++ b/contrib/convert-repo	Fri Jan 12 15:23:30 2007 +0100
> @@ -23,7 +23,17 @@
>  # on each commit copied, so convert-repo can be interrupted and can
>  # be run repeatedly to copy new commits.
>  
> -import sys, os, zlib, sha, time, re, locale
> +import sys, os, zlib, sha, time, re
> +# work around broken locale on darwin
> +if sys.platform != 'darwin':
> +    import locale
> +else:
> +    try:
> +        sys.platform = 'posix'
> +        import locale
> +    finally:
> +        sys.platform = 'darwin'
> +
>  os.environ["HGENCODING"] = "utf-8"
>  from mercurial import hg, ui, util, fancyopts



>  
> diff -r 6ea8a3b805ee -r f65f155be5c1 mercurial/util.py
> --- a/mercurial/util.py	Wed Jan 10 20:35:27 2007 +0100
> +++ b/mercurial/util.py	Fri Jan 12 15:23:30 2007 +0100
> @@ -14,7 +14,16 @@ platform-specific details from the core.
>  
>  from i18n import _
>  import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile
> -import os, threading, time, calendar, ConfigParser, locale
> +import os, threading, time, calendar, ConfigParser
> +# work around broken locale on darwin
> +if sys.platform != 'darwin':
> +    import locale
> +else:
> +    try:
> +        sys.platform = 'posix'
> +        import locale
> +    finally:
> +        sys.platform = 'darwin'
>  
>  _encoding = os.environ.get("HGENCODING") or locale.getpreferredencoding() \
>              or "ascii"

You've failed to describe the brokenness, but if it's what I think it
is, I'm not convinced this is correct.

Basically, the test of whether it works properly is: when you write a
file with a typical editor on a platform, does the encoding you get
agree with the encoding Mercurial thinks you're using.

>From what I can tell, most native OS X apps ignore LC_CTYPE and use
MacRoman on a typical system. This includes things like TextEdit and
other native editors. Perhaps there's another way to set the default
encoding systemwide, but it isn't done through LC_CTYPE.

This puts us into a broken situation similar to the one we have on
Windows where the 'console' has one notion of encoding (LC_CTYPE) and
the rest of the system has another.

And just like with Windows, the most sensible thing is to ignore the
console encoding and use the system one with the ability to override
it with HGEDITOR if we're doing something nonstandard. Because it's
important to work with native editors by default.

(see http://selenic.com/mercurial/wiki/index.cgi/Character_Encoding_On_Windows
for comparison)

-- 
Mathematics is the supreme nostalgia of our time.


More information about the Mercurial-devel mailing list