git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Karsten Blees <karsten.blees@gmail.com>,
	Jeff Hostetler <jeffhost@microsoft.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 0/2] mingw: rework the environment handling
Date: Tue, 30 Oct 2018 02:22:27 -0700 (PDT)	[thread overview]
Message-ID: <pull.57.git.gitgitgadget@gmail.com> (raw)

Once upon a time, the Git for Windows project had to decide what to do about
Unicode support, including how to deal with the environment. Karsten Blees
spent a ton of work on this, culminating in the final version
[https://groups.google.com/d/msg/msysgit/wNZAyScbJG4/viWz2KXU0VYJ] which
made it into Git for Windows and at least partially into core Git, too.

The environment handling in particular is a bit tricky: Windows actually has 
two copies of the environment, one encoded in UTF-16, and the other one in
the local encoding. Since we want UTF-8 encoded values (which is not an
option for the local encoding), we had to convert from/to the UTF-16
environment.

At the time those patches were developed, there were so many getenv()/
putenv() calls in Git's code base that it seemed the best solution to
convert the entire environment into UTF-8 in one go, at startup.

There are good reasons for us to change that paradigm now (and this patch
series does that):

 * The method we use does not work with modern MSVC runtimes (__environ can
   no longer be overridden).
 * Our method of having a malloc()ed environment wreaks havoc if a library
   we use calls MSVC's version of setenv() (I am looking at you, libcurl).
 * In the meantime, core Git's usage of getenv()/putenv() was reduced
   dramatically (for unrelated reasons), so that it is actually advantageous
   nowadays to convert on the fly, i.e. with each getenv()/putenv() call,
   rather than doing one wholesale conversion at process startup. See also
   the commit message of the second patch.

Note: in contrast to other patches flowing from Git for Windows to Git these
days this patch has not been in Git for Windows for ages. Its approach has
been tested in some MS Visual C++ builds (thanks, Jeff Hostetler!), though,
so I am quite confident that it is correct, and the test suite agrees.

Johannes Schindelin (2):
  t7800: fix quoting
  mingw: reencode environment variables on the fly (UTF-16 <-> UTF-8)

 compat/mingw.c      | 280 ++++++++++++++++++++++++++------------------
 compat/mingw.h      |  32 ++++-
 t/t7800-difftool.sh |   2 +-
 3 files changed, 197 insertions(+), 117 deletions(-)


base-commit: c670b1f876521c9f7cd40184bf7ed05aad843433
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-57%2Fdscho%2Fmingw-utf-8-env-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-57/dscho/mingw-utf-8-env-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/57
-- 
gitgitgadget

             reply	other threads:[~2018-10-30  9:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-30  9:22 Johannes Schindelin via GitGitGadget [this message]
2018-10-30  9:22 ` [PATCH 1/2] t7800: fix quoting Johannes Schindelin via GitGitGadget
2018-10-30  9:22 ` [PATCH 2/2] mingw: reencode environment variables on the fly (UTF-16 <-> UTF-8) Johannes Schindelin via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.57.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jeffhost@microsoft.com \
    --cc=karsten.blees@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).