threads / rfc / 29362

RFC v3git on Mac OS and precomposed unicode

Subject: [RFC][PATCH v3] git on Mac OS and precomposed unicode

## tl;dr

2 messages between Jan 13, 2012 and Jan 13, 2012. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

tb· Jan 13, 2012, 21:53 UTC · lore
Changes since V2:
- renamed compat/darwin.[ch] into compat/precomposed_utf8.[ch]
- builtin/init-db.c: use probe_utf8_pathname_composition()
- fix in reencode_string_iconv(): Don't call iconv_close()
- Allways convert all arguments, no special handling for "git commit"
Changes since last version:
- Improved testcase t/t3910-mac-os-precompose.sh:
  test "git commit -- pathspec" (Thanks Junio)
- Improved the converting of argv[] for "git commit"

=============== Purpose: This patch is a suggestion to work around the unpleasenties when Mac OS is decomposing unicode filenames.

The suggested change:
a) is only used under Mac OS
b) can be switched off by a configuration variable
c) is optimized to handle ASCII only filename
d) will improve the interwork between Mac OS, Linux and Windows*
   via git push/pull, using USB sticks (technically speaking VFAT)
   or mounted network shares using samba.
* (Not all Windows versions support UTF-8 yet:
   Msysgit needs the unicode branch, cygwin supports UTF-8 since 1.7)

Runtime configuration: A new confguration variable is added: "core.precomposedunicode" This variable is only used on Mac OS. If set to false, git behaves exactly as older versions of git. When a new git version is installed and there is a repository where the configuration "core.precomposedunicode" is not present, the new git is backward compatible.

When core.precomposedunicode=true, all filenames are stored in precomposed unicode in the index (technically speaking precomposed UTF-8). Even when readdir() under Mac OS returns filenames as decomposed.

Implementation: Two files are added to the "compat" directory, darwin.h and darwin.c. They implement basically 4 new functions: precomposed_utf8_opendir(), precomposed_utf8_readdir(), precomposed_utf8_closedir() argv_precompose()

Compile time configuration: A new compiler option PRECOMPOSED_UNICODE is introduced in the Makefile, so that the patch can be switched off completely at compile time.

No decomposed file names in a git repository: In order to prevent that ever a file name in decomposed unicode is entering the index, a "brute force" attempt is taken: all arguments into git (technically argv[1]..argv[n]) are converted into precomposed unicode. This is done in git.c by calling argv_precompose(). This function is actually a #define, and it is only defined under Mac OS. Nothing is converted on any other OS.

Implementation details: The main work is done in precomposed_utf8_readdir() and argv_precompose(). The conversion into precomposed unicode is done by using iconv, where decomposed is denoted by "UTF-8-MAC" and precomposed is "UTF-8". When already precomposed unicode is precomposed, the string is returned unchanged.

Thread save: Since there is no need for argv_precompose()to be thread-save, one iconv instance is created at the beginning and kept for all conversions. Even readdir() is not thread-save, so that precomposed_utf8_opendir() will call iconv_open() once and keep the instance for all calls of precomposed_utf8_readdir() until precomposed_utf8_close() is called.

Auto sensing: When creating a new git repository with "git init" or "git clone", the "core.precomposedunicode" will be set automatically to "true" or "false".

Typically core.precomposedunicode is "true" on HFS and VFAT. It is even true for file systems mounted via SAMBA onto a Linux box, and "false" for drives mounted via NFS onto a Linux box.

New test case: The new t3910-mac-os-precompose.sh is added to check if a filename can be reached either in precomposed or decomposed unicode (NFC or NFD).

Torsten Bögershausen (1):
  git on Mac OS and precomposed unicode
 Documentation/config.txt     |    9 ++
 Makefile                     |    3 +
 builtin/init-db.c            |    2 +
 compat/precomposed_utf8.c    |  213 ++++++++++++++++++++++++++++++++++++++++++
 compat/precomposed_utf8.h    |   39 ++++++++
 git-compat-util.h            |    9 ++
 git.c                        |    1 +
 t/t0050-filesystem.sh        |    1 +
 t/t3910-mac-os-precompose.sh |  117 +++++++++++++++++++++++
 9 files changed, 394 insertions(+), 0 deletions(-)
 create mode 100644 compat/precomposed_utf8.c
 create mode 100644 compat/precomposed_utf8.h
 create mode 100755 t/t3910-mac-os-precompose.sh
-- 
1.7.8.rc0.43.gb49a8
Jonathan Nieder· Jan 13, 2012, 22:56 UTC · re: tb · lore

Re: [RFC][PATCH v3] git on Mac OS and precomposed unicode

Hi,
tb wrote:
> Purpose:
[...]
> Runtime configuration:
[...]
> Implementation:
[...]
> Compile time configuration:
[...]
> Implementation details:
[....]
> Thread safety:
[...]
> Auto sensing:
[...]
> New test case:

This information, to the extent that it is useful at all, belongs in the commit log. That is, the commit message should concisely say everything a person would want to know when reading a patch, whether reading it to review it for inclusion, to make sure it still works when making a related change, to consider whether it is safe to upgrade to a version including the change, to understand what is happening when a bug is tracked down to be caused by that commit, or for some other reason.

So please do not use a cover letter that separates this information when sending a single patch.

> Changes since [...]

This kind of information that does not belong in the commit message can go after the "---" in the same message as the patch.

I haven't read the patch yet, except to glance at it and see some nitpicks I can mention later (e.g., source files should not #include anything else before git-compat-util.h or cache.h), and the approach seems likely to be sane; I'm mentioning this to help you present the information in a way that can save myself and other reviewers some trouble for the next round.

Thanks much for your work, and hope that helps.

Regards, Jonathan

← back to recent threads