{"thread":{"id":"29323","subject":"[RFC][PATCH v2] git on Mac OS and precomposed unicode","startedAt":"2012-01-09T16:45:24Z","lastAt":"2012-01-09T16:45:24Z","messageCount":1,"participants":["Torsten Bögershausen"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"182168","messageId":"201201091745.25252.tboegi@web.de","threadId":"29323","inReplyTo":null,"subject":"[RFC][PATCH v2] git on Mac OS and precomposed unicode","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2012-01-09T16:45:24Z","receivedAt":"2012-01-09T16:45:24Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"Changes since last version:\n- Improved testcase t/t3910-mac-os-precompose.sh:\n  test \"git commit -- pathspec\" (Thanks Junio)\n- Improved the converting of argv[] for \"git commit\"\n\n===============\nPurpose:\nThis patch is a suggestion to work around the unpleasenties\nwhen Mac OS is decomposing unicode filenames.\n\nThe suggested change:\na) is only used under Mac OS\nb) can be switched off by a configuration variable\nc) is optimized to handle ASCII only filename\nd) will improve the interwork between Mac OS, Linux and Windows*\n   via git push/pull, using USB sticks (technically speaking VFAT)\n   or mounted network shares using samba.\n\n* (Not all Windows versions support UTF-8 yet:\n   Msysgit needs the unicode branch, cygwin supports UTF-8 since 1.7)\n\n\nRuntime configuration:\nA new confguration variable is added: \"core.precomposedunicode\"\nThis variable is only used on Mac OS.\nIf set to false, git behaves exactly as older versions of git.\nWhen a new git version is installed and there is a repository\nwhere the configuration \"core.precomposedunicode\" is not present,\nthe new git is backward compatible.\n\nWhen core.precomposedunicode=true, all filenames are stored in precomposed\nunicode in the index (technically speaking precomposed UTF-8).\nEven when readdir() under Mac OS returns filenames as decomposed.\n\nImplementation:\nTwo files are added to the \"compat\" directory, darwin.h and darwin.c.\nThey implement basically 3 new functions:\ndarwin_opendir(), darwin_readdir() and darwin_closedir().\n\n\nCompile time configuration:\nA new compiler option PRECOMPOSED_UNICODE is introduced in the Makefile,\nso that the patch can be switched off completely at compile time.\n\nNo decomposed file names in a git repository:\nIn order to prevent that ever a file name in decomposed unicode is entering\nthe index, a \"brute force\" attempt is taken:\nall arguments into git (technically argv[1]..argv[n]) are converted into\nprecomposed unicode.\nThis is done in git.c by calling argv_precompose() for all commands:\nFor \"git commit\" all args after \"--\" are converted,\nfor all other commands all argv[] is converted.\n\nThis function is actually a #define, and it is only defined under Mac OS.\nNothing is converted on any other OS.\n\nImplementation details:\nThe main work is done in darwin_readdir() and argv_precompose().\nThe conversion into precomposed unicode is done by using iconv,\nwhere decomposed is denoted by \"UTF-8-MAC\" and precomposed is \"UTF-8\".\nWhen already precomposed unicode is precomposed, the string is returned\nunchanged.\n\nThread save:\nSince there is no need for argv_precompose()to be thread-save, one iconv\ninstance is created at the beginning and kept for all conversions.\nEven readdir() is not thread-save, so that darwin_opendir() will call\niconv_open() once and keep the instance for all calls of darwin_readdir()\nuntil darwin_close() is called.\n\nAuto sensing:\nWhen creating a new git repository with \"git init\" or \"git clone\", the\n\"core.precomposedunicode\" will be set automatically to \"true\" or \"false\".\n\nTypically core.precomposedunicode is \"true\" on HFS and VFAT.\nIt is even true for file systems mounted via SAMBA onto a Linux box,\nand \"false\" for drives mounted via NFS onto a Linux box.\n\n\nNew test case:\nThe new t3910-mac-os-precompose.sh is added to check if a filename\ncan be reached either in precomposed or decomposed unicode (NFC or NFD).\n\n\nTorsten Bögershausen (1):\n  git on Mac OS and precomposed unicode\n\n Documentation/config.txt     |    9 ++\n Makefile                     |    3 +\n builtin/init-db.c            |   22 +++++\n compat/darwin.c              |  208 ++++++++++++++++++++++++++++++++++++++++++\n compat/darwin.h              |   31 ++++++\n git-compat-util.h            |    8 ++\n git.c                        |    1 +\n t/t0050-filesystem.sh        |    1 +\n t/t3910-mac-os-precompose.sh |  117 +++++++++++++++++++++++\n 9 files changed, 400 insertions(+), 0 deletions(-)\n create mode 100644 compat/darwin.c\n create mode 100644 compat/darwin.h\n create mode 100755 t/t3910-mac-os-precompose.sh\n\n-- \n1.7.8.rc0.43.gb49a8\n"}]}