git on Mac OS and precomposed unicode
Subsystems (2)
RFC PATCH 1/1 git on Mac OS and precomposed unicode
Allow git on Mac OS to store file names in the index in precomposed unicode, while the file system used decomposed unicode.
When a file called "LATIN CAPITAL LETTER A WITH DIAERESIS" (in utf-8 encoded as 0xc3 0x84) is created,
the filesystem converts "precomposed unicode" into "decomposed unicode", which means that readdir() will return 0x41 0xcc 0x88.
When true, git reverts the unicode decomposition of filenames. This is useful when pulling/pushing from repositories containing utf-8 encoded filenames using precomposed utf-8 (like Linux).
This feature is automatically switched on when "git init" is run, and the file system is doing UTF-8 decompostion.
(Which has been observed on HFS+, SMBFS and VFAT, but not on NFS) It can be switched off by setting core.macosforcenfc=false
It is implemented by re-defining the readdir() functions. File names are converted into precomposed UTF-8.
--- Documentation/config.txt | 9 ++ Makefile | 3 + builtin/init-db.c | 22 +++++ compat/darwin.c | 200 ++++++++++++++++++++++++++++++++++++++++++ compat/darwin.h | 31 +++++++ git-compat-util.h | 8 ++ git.c | 1 + t/t0050-filesystem.sh | 1 + t/t3910-mac-os-precompose.sh | 104 ++++++++++++++++++++++ 9 files changed, 379 insertions(+), 0 deletions(-) create mode 100644 compat/darwin.c create mode 100644 compat/darwin.h create mode 100755 t/t3910-mac-os-precompose.sh
Documentation/config.txt +9 -0
@@ -175,6 +175,15 @@ The default is false, except linkgit:git-clone[1] or linkgit:git-init[1] will probe and set core.ignorecase true if appropriate when the repository is created. +core.precomposedunicode:: + This option is only used by Mac OS implementation of git. + When core.precomposedunicode=true, + git reverts the unicode decomposition of filenames done by Mac OS. + This is useful when pulling/pushing from repositories containing utf-8 + encoded filenames using precomposed unicode (like Linux). + When false, file names are handled fully transparent by git. + If in doubt, set core.precomposedunicode=false. + core.trustctime:: If false, the ctime differences between the index and the working tree are ignored; useful when the inode change time
Makefile +3 -0
@@ -519,6 +519,7 @@ LIB_H += compat/bswap.h LIB_H += compat/cygwin.h LIB_H += compat/mingw.h LIB_H += compat/obstack.h +LIB_H += compat/darwin.h LIB_H += compat/win32/pthread.h LIB_H += compat/win32/syslog.h LIB_H += compat/win32/poll.h
@@ -884,6 +885,8 @@ ifeq ($(uname_S),Darwin) endif NO_MEMMEM = YesPlease USE_ST_TIMESPEC = YesPlease + COMPAT_OBJS += compat/darwin.o + BASIC_CFLAGS += -DPRECOMPOSED_UNICODE endif ifeq ($(uname_S),SunOS) NEEDS_SOCKET = YesPlease
builtin/init-db.c +22 -0
@@ -290,6 +290,28 @@ static int create_default_files(const char *template_path)strcpy (path + len,"CoNfIg" );if (!access (path,F_OK ))git_config_set ("core.ignorecase" ,"true" ); +#if defined (PRECOMPOSED_UNICODE ) + { +const static char *auml_nfc ="\xc3\xa4" ; +const static char *auml_nfd ="\x61\xcc\x88" ; +int output_fd; + path[len] =0 ; +strcpy (path + len, auml_nfc); + output_fd =open (path,O_CREAT |O_EXCL |O_RDWR ,0600 ); +if (output_fd >=0 ) { +close (output_fd); + path[len] =0 ; +strcpy (path + len, auml_nfd); +if (0 ==access (path,R_OK )) +git_config_set ("core.precomposedunicode" ,"true" ); +else +git_config_set ("core.precomposedunicode" ,"false" ); + path[len] =0 ; +strcpy (path + len, auml_nfc); +unlink (path); + } + } +#endif }return reinit;
compat/darwin.c new file +200 -0
200 lines not on this page · raw message
compat/darwin.h new file +31 -0
@@ -0,0 +1,31 @@ +#ifndef __DARWIN_H__ +#include <sys/stat.h> +#include <sys/types.h> +#include <dirent.h> +#include <iconv.h> + + +typedef struct { +iconv_t ic_precompose; +DIR *dirp; +struct dirent dirent_nfc; +}DARWIN_DIR ; + +char *str_precompose (const char *in,iconv_t ic_precompose); + +void argv_precompose (int argc,const char **argv); + +DARWIN_DIR *darwin_opendir (const char *dirname); +struct dirent *darwin_readdir (DARWIN_DIR *dirp); +int darwin_closedir (DARWIN_DIR *dirp); + +#ifndef __DARWIN_C__ +#define opendir (n) darwin_opendir(n) +#define readdir (d) darwin_readdir(d) +#define closedir (d) darwin_closedir(d) +#define DIR DARWIN_DIR + +#endif /* __DARWIN_C__ */ + +#define __DARWIN_H__ +#endif /* __DARWIN_H__ */
git-compat-util.h +8 -0
@@ -90,6 +90,14 @@#include <windows.h> #endif +#if defined (PRECOMPOSED_UNICODE ) +#include "compat/darwin.h" +#else +#define str_precompose (in,i_nfd2nfc) (NULL) +#define argv_precompose (c,v) + +#endif +#include <unistd.h> #include <stdio.h> #include <sys/stat.h>
git.c +1 -0
@@ -298,6 +298,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) startup_info->have_repository) /* get_git_dir() may set up repo, avoid that */trace_repo_setup (prefix); } +argv_precompose (argc, argv);commit_pager_choice ();if (!help && p->option &NEED_WORK_TREE )
t/t0050-filesystem.sh +1 -0
@@ -126,6 +126,7 @@ test_expect_success "setup unicode normalization tests" ' test_create_repo unicode && cd unicode && + git config core.precomposedunicode false && touch "$aumlcdiar" && git add "$aumlcdiar" && git commit -m initial &&
t/t3910-mac-os-precompose.sh new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
1.7.8.rc0.43.gb49a8
BTW, about the names, e.g. "darwin.c" etc -- is this code actually Darwin-specific, or simply Systems-that-happen-to-force-decomposed- unicode specific?
If the latter, maybe more generic names might be better.
Thanks,
-Miles
Signature · 2 lines
`To alcohol! The cause of, and solution to, all of life's problems' --Homer J. Simpson
Quoted 10 lines · Miles Bader
BTW, about the names, e.g. "
darwin.c" etc -- is this code actually Darwin-specific, or simply Systems-that-happen-to-force-decomposed- unicode specific?If the latter, maybe more generic names might be better.
Thanks,
-Miles
As far as I know, Mac OS (darwin) is the only existing OS which likes decomposed unicode so much, that forces decomposed unicode that way. /Torsten