[PATCH 2 of 6] Determine default locale encoding and stdio encoding on start-up
Thomas Arendsen Hein
thomas at intevation.de
Tue Nov 14 07:36:43 UTC 2006
* Matt Mackall <mpm at selenic.com> [20061113 19:04]:
> On Mon, Nov 13, 2006 at 12:53:44PM +0600, Andrey wrote:
> > On 13 November 2006 (Mon) 06:10, Matt Mackall wrote:
> > > On Mon, Nov 13, 2006 at 12:49:25AM +0700, Andrey wrote:
> > > > @@ -48,6 +48,15 @@ class ui(object):
> > > > self.ucdata = None
> > > > self.readconfig(util.rcpath())
> > > > self.updateopts(verbose, debug, quiet, interactive)
> > > > +
> > > > + self.encodings = {}
> > > > + self.encodings['default'] = (self.config("ui", "encoding")
> > > > + or
> > > > locale.getpreferredencoding()) + # windows may use different
> > > > encoding for stdio
> > > > + self.encodings['stdio'] = (self.config("ui",
> > > > "stdio_encoding") + or
> > > > self.config("ui", "encoding") + or
> > > > sys.stdout.encoding or sys.stdin.encoding +
> > > > or self.encodings['default'])
> > >
> > > Again, should be in util.py. Don't know if it makes sense to bother
> > > with two different config options. When is that useful?
> >
> > I actually borrowed most of the code from
> > http://www.selenic.com/mercurial/bts/issue156. :-) Having two different
> > encodings is nessessary on Windows and maybe on other esotheric systems.
> > And 'stdio_encoding' option could be useful if autodetection of encoding
> > fails.
>
> Just because Windows does it doesn't mean its useful. What are the
> scenarios where Windows needs it?
type foo | hg something | more
You might have noticed the expression "sys.stdout.encoding or
sys.stdin.encoding" which is to circumvent the problem that Windows
isn't able to determine the encoding of stdout, if you pipe to more.
> > It would be nice indeed to move that code to util.py, but it needs access to
> > config, and for some reason config loading is done in ui.py (I'd personally
> > prefer having separate config.py module and read config file on first module
> > import). Could someone comment on this?
>
> I'm not yet convinced locale support needs access to the config. If
> the average internationalized app needed its own config tweaks,
> everyone would just give up and use ASCII.
LC_CTYPE=foo hg something would work for most cases, too, except on
non-POSIX systems. It is not essential, but having a way to override
the possibly wrong assumptions made by python or hg isn't wrong.
And yes, most people just give up and use ASCII.
Thomas
--
Email: thomas at intevation.de
http://intevation.de/~thomas/
More information about the Mercurial-devel
mailing list