[PATCH 2 of 8] determine default locale encoding and stdio encoding on start-up

Matt Mackall mpm at selenic.com
Mon Nov 20 11:36:20 CST 2006


On Mon, Nov 20, 2006 at 05:29:52PM +0700, Andrey wrote:
> diff -r c1622a4837a2 -r cba3d15b1f26 mercurial/ui.py
> --- a/mercurial/ui.py	Sun Nov 12 00:29:30 2006 +0600
> +++ b/mercurial/ui.py	Sun Nov 12 21:23:32 2006 +0600
> @@ -8,7 +8,7 @@ from i18n import gettext as _
>  from i18n import gettext as _
>  from demandload import *
>  demandload(globals(), "errno getpass os re socket sys tempfile")
> -demandload(globals(), "ConfigParser traceback util")
> +demandload(globals(), "ConfigParser traceback util locale")
>  
>  def dupconfig(orig):
>      new = util.configparser(orig.defaults())
> @@ -49,6 +49,15 @@ class ui(object):
>              self.readconfig(util.rcpath())
>              self.check_trusted = True
>              self.updateopts(verbose, debug, quiet, interactive)
> +
> +            self.encodings = {}
> +            self.encodings["default"] = (self.config("ui", "encoding")
> +                                        or locale.getpreferredencoding())

I'm afraid this config approach doesn't really work.

When you're likely to need to tweak this, you're like to need it to
have several settings. Consider:

Laptop: runs modern all UTF-8 distro
Home machine: runs with a Russian character set
Work machine: runs with ASCII/Latin-1

Now you can sit down at your desk at work with your laptop, and ssh
from both your laptop and your work machine back to your home machine
and suddenly things get complicated. If you override settings in
.hgrc, you'll break something on another machine. That's because
encoding is a property of the terminal session and not the machine it
happens to be running on.

Thus, we need to attach any charset override mechanism to the terminal
session and not the config. Which means it should go in the
environment along with the rest of the locale settings.

Which means this should all move out of ui and into util!

-- 
Mathematics is the supreme nostalgia of our time.


More information about the Mercurial-devel mailing list