D7550: chg: fix chg to work with py3.7+ "coercing" the locale

spectral (Kyle Lippincott) phabricator at mercurial-scm.org
Wed Dec 11 18:14:34 EST 2019

spectral added a comment.

  In D7550#111235 <https://phab.mercurial-scm.org/D7550#111235>, @yuja wrote:
  >>   When the environment is empty (specifically: it doesn't contain LC_ALL,
  >>   LC_CTYPE, or LANG), Python will "coerce" the locale environment variables to be
  >>   a UTF-8 capable one. It sets LC_CTYPE in the environment, and this breaks chg,
  >>   since chg operates by:
  >>   - start hg, using whatever environment the user has when chg starts
  >>   - hg stores a hash of this "original" environment, but python has already set LC_CTYPE even though the user doesn't have it in their environment
  >>   - chg calls setenv over the commandserver. This clears the environment inside of hg and sets it to be exactly what the environment in chg is (without LC_CTYPE).
  >>   - chg calls validate to ensure that the environment hg is using (after the setenv call) is the one that the chg process has - if not, it is assumed the user changed their environment and we should use a different server. This will *never* be true in this situation because LC_CTYPE was removed.
  > Sigh. Can we work around this weird behavior by making chg do
  > `putenv("PYTHONCOERCECLOCALE=0")`? I think it's simple and more desired
  > behavior than the default of Python 3.
  I had considered that and was concerned it would create an observable, surprising/confusing difference between chg and non-chg: if chg sets PYTHONCOERCECLOCALE=0, hg won't have LC_CTYPE in the environment, and it WILL have PYTHONCOERCECLOCALE in the environment. When it starts external tools (like merge tools), this may change behavior in some observable fashion, and if the user stops using chg and uses just plain hg, it will have LC_CTYPE in the environment. This would probably be difficult to debug - users (at least the ones I interact with) often don't tell us they're using chg, if they even know that they are. (Sometimes users don't even know they're using chg, such as via their IDE's Mercurial integration, but that's probably not actually a problem here - the IDE would be responsible for making this work, not end users).
  I don't know the reason why Python is doing this at all, so maybe my concern is purely hypothetical and not really a problem?

  rHG Mercurial



To: spectral, #hg-reviewers
Cc: yuja, mjpieters, mercurial-devel

More information about the Mercurial-devel mailing list