From f1d8529445e627801b433fffcc034ad90a7e99ff Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Wed, 16 Dec 2009 22:20:55 +0100 Subject: [PATCH] core.hidedotfiles: only hide '.git' dir by default At least for cross-platform projects, it makes sense to hide the files starting with a dot, as this is the behavior on Unix/MacOSX. However, at least Eclipse has problems interpreting the hidden flag correctly, so the default is to hide only the .git/ directory. The config setting core.hideDotFiles therefore supports not only 'true' and 'false', but also 'dotGitOnly'. [jes: clarified the commit message, made git init respect the setting by marking the .git/ directory only after reading the config, and added documentation] Signed-off-by: Erik Faye-Lund Signed-off-by: Johannes Schindelin --- Documentation/config.txt | 2 ++ builtin-init-db.c | 1 + cache.h | 8 +++++++- compat/mingw.c | 16 ++++++++++++---- compat/mingw.h | 3 +++ config.c | 4 ++++ environment.c | 2 +- git-compat-util.h | 4 ++++ 8 files changed, 34 insertions(+), 6 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index f9fd44e783..6370d6f6f7 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -136,6 +136,8 @@ core.fileMode:: core.hideDotFiles:: (Windows-only) If true (which is the default), mark newly-created directories and files whose name starts with a dot as hidden. + If 'dotGitOnly', only the .git/ directory is hidden, but no other + files starting with a dot. core.ignoreCygwinFSTricks:: This option is only used by Cygwin implementation of Git. If false, diff --git a/builtin-init-db.c b/builtin-init-db.c index dd84caecbc..8640643675 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -298,6 +298,7 @@ int init_db(const char *template_dir, unsigned int flags) check_repository_format(); reinit = create_default_files(template_dir); + mark_as_git_dir(get_git_dir()); sha1_dir = get_object_directory(); len = strlen(sha1_dir); diff --git a/cache.h b/cache.h index 767a50e4ed..d3bfe0d36f 100644 --- a/cache.h +++ b/cache.h @@ -525,7 +525,13 @@ extern int auto_crlf; extern int read_replace_refs; extern int fsync_object_files; extern int core_preload_index; -extern int hide_dotfiles; + +enum hide_dotfiles_type { + HIDE_DOTFILES_FALSE = 0, + HIDE_DOTFILES_TRUE, + HIDE_DOTFILES_DOTGITONLY, +}; +extern enum hide_dotfiles_type hide_dotfiles; enum safe_crlf { SAFE_CRLF_FALSE = 0, diff --git a/compat/mingw.c b/compat/mingw.c index 2424380cba..45c5a19aaa 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -4,8 +4,8 @@ #include #include #include "../strbuf.h" +#include "../cache.h" -extern int hide_dotfiles; unsigned int _CRT_fmode = _O_BINARY; static int err_win_to_posix(DWORD winerr) @@ -130,11 +130,17 @@ static int make_hidden(const char *path) return -1; } +void mingw_mark_as_git_dir(const char *dir) +{ + if (hide_dotfiles != HIDE_DOTFILES_FALSE && make_hidden(dir)) + warning("Failed to make '%s' hidden", dir); +} + #undef mkdir int mingw_mkdir(const char *path, int mode) { int ret = mkdir(path); - if (!ret && hide_dotfiles) { + if (!ret && hide_dotfiles == HIDE_DOTFILES_TRUE) { /* * In Windows a file or dir starting with a dot is not * automatically hidden. So lets mark it as hidden when @@ -168,7 +174,8 @@ int mingw_open (const char *filename, int oflags, ...) if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) errno = EISDIR; } - if ((oflags & O_CREAT) && fd >= 0 && hide_dotfiles) { + if ((oflags & O_CREAT) && fd >= 0 && + hide_dotfiles == HIDE_DOTFILES_TRUE) { /* * In Windows a file or dir starting with a dot is not * automatically hidden. So lets mark it as hidden when @@ -186,7 +193,8 @@ FILE *mingw_fopen (const char *filename, const char *mode) { int hide = 0; FILE *file; - if (hide_dotfiles && basename((char*)filename)[0] == '.') + if (hide_dotfiles == HIDE_DOTFILES_TRUE && + basename((char*)filename)[0] == '.') hide = access(filename, F_OK); file = fopen(filename, mode); diff --git a/compat/mingw.h b/compat/mingw.h index 45cb239872..364cc72bae 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -231,6 +231,9 @@ int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format void mingw_open_html(const char *path); #define open_html mingw_open_html +void mingw_mark_as_git_dir(const char *dir); +#define mark_as_git_dir mingw_mark_as_git_dir + /* * helpers */ diff --git a/config.c b/config.c index 49010e4890..c8cdb81633 100644 --- a/config.c +++ b/config.c @@ -504,6 +504,10 @@ static int git_default_core_config(const char *var, const char *value) } if (!strcmp(var, "core.hidedotfiles")) { + if (value && !strcasecmp(value, "dotgitonly")) { + hide_dotfiles = HIDE_DOTFILES_DOTGITONLY; + return 0; + } hide_dotfiles = git_config_bool(var, value); return 0; } diff --git a/environment.c b/environment.c index ea1abbf289..ccbae176ea 100644 --- a/environment.c +++ b/environment.c @@ -50,7 +50,7 @@ enum push_default_type push_default = PUSH_DEFAULT_MATCHING; #endif enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE; int grafts_replace_parents = 1; -int hide_dotfiles = 1; +enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY; /* Parallel index stat data preload? */ int core_preload_index = 0; diff --git a/git-compat-util.h b/git-compat-util.h index ef60803384..db19559bc3 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -464,4 +464,8 @@ void git_qsort(void *base, size_t nmemb, size_t size, */ int unlink_or_warn(const char *path); +#ifndef mark_as_git_dir +#define mark_as_git_dir(x) /* noop */ +#endif + #endif