[PATCH v3 0/2] Support marking .git/ (or all files) as hidden on Windows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Windows does not share Unix' convention that files and directories whose
names start with a dot are hidden. Hence `.git/`, for example, is in
plain view, and caused quite a bit of trouble: some users wanted to peek
inside and did not understand what it contains, others modified files.

There was a stream of bug reports, until Git for Windows introduced the
(opt-out) option to hide at least the .git/ directory by default. The
option is configured via the config setting core.hideDotFiles, with the
possible values false, true and dotGitOnly (the latter being the
default).

This is a heavily version of patches we carried in Git for Windows for
way too long without submitting them upstream.

This iteration addresses Junio's most recent round of concerns. Oh, and
while at it, it also avoids setting attributes unnecessarily.


Johannes Schindelin (2):
  mingw: introduce the 'core.hideDotFiles' setting
  mingw: remove unnecessary definition

 Documentation/config.txt |  6 ++++
 cache.h                  |  7 +++++
 compat/mingw.c           | 74 ++++++++++++++++++++++++++++++++++++++++++++++++
 compat/mingw.h           |  3 --
 config.c                 |  8 ++++++
 environment.c            |  1 +
 t/t0001-init.sh          | 30 ++++++++++++++++++++
 t/t5611-clone-config.sh  | 20 +++++++++++++
 8 files changed, 146 insertions(+), 3 deletions(-)

Published-As: https://github.com/dscho/git/releases/tag/hide-dotgit-v3
Interdiff vs v2:

 diff --git a/cache.h b/cache.h
 index 743b081..5f72f59 100644
 --- a/cache.h
 +++ b/cache.h
 @@ -704,7 +704,7 @@ extern int auto_comment_line_char;
  enum hide_dotfiles_type {
  	HIDE_DOTFILES_FALSE = 0,
  	HIDE_DOTFILES_TRUE,
 -	HIDE_DOTFILES_DOTGITONLY,
 +	HIDE_DOTFILES_DOTGITONLY
  };
  extern enum hide_dotfiles_type hide_dotfiles;
  
 diff --git a/compat/mingw.c b/compat/mingw.c
 index 3ecde84..a8218e6 100644
 --- a/compat/mingw.c
 +++ b/compat/mingw.c
 @@ -318,12 +318,12 @@ static inline int needs_hiding(const char *path)
  
  static int set_hidden_flag(const wchar_t *path, int set)
  {
 -	DWORD attribs = GetFileAttributesW(path);
 +	DWORD original = GetFileAttributesW(path), modified;
  	if (set)
 -		attribs |= FILE_ATTRIBUTE_HIDDEN;
 +		modified = original | FILE_ATTRIBUTE_HIDDEN;
  	else
 -		attribs &= ~FILE_ATTRIBUTE_HIDDEN;
 -	if (SetFileAttributesW(path, attribs))
 +		modified = original & ~FILE_ATTRIBUTE_HIDDEN;
 +	if (original == modified || SetFileAttributesW(path, modified))
  		return 0;
  	errno = err_win_to_posix(GetLastError());
  	return -1;
 @@ -377,7 +377,7 @@ int mingw_open (const char *filename, int oflags, ...)
  		if (fd < 0 && errno == EACCES)
  			fd = _wopen(wfilename, oflags & ~O_CREAT, mode);
  		if (fd >= 0 && set_hidden_flag(wfilename, 1))
 -			warning("Could not mark '%s' as hidden.", filename);
 +			warning("could not mark '%s' as hidden.", filename);
  	}
  	return fd;
  }
 @@ -419,12 +419,12 @@ FILE *mingw_fopen (const char *filename, const char *otype)
  		xutftowcs(wotype, otype, ARRAY_SIZE(wotype)) < 0)
  		return NULL;
  	if (hide && !access(filename, F_OK) && set_hidden_flag(wfilename, 0)) {
 -		error("Could not unhide %s", filename);
 +		error("could not unhide %s", filename);
  		return NULL;
  	}
  	file = _wfopen(wfilename, wotype);
  	if (file && hide && set_hidden_flag(wfilename, 1))
 -		warning("Could not mark '%s' as hidden.", filename);
 +		warning("could not mark '%s' as hidden.", filename);
  	return file;
  }
  
 @@ -439,12 +439,12 @@ FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)
  		xutftowcs(wotype, otype, ARRAY_SIZE(wotype)) < 0)
  		return NULL;
  	if (hide && !access(filename, F_OK) && set_hidden_flag(wfilename, 0)) {
 -		error("Could not unhide %s", filename);
 +		error("could not unhide %s", filename);
  		return NULL;
  	}
  	file = _wfreopen(wfilename, wotype, stream);
  	if (file && hide && set_hidden_flag(wfilename, 1))
 -		warning("Could not mark '%s' as hidden.", filename);
 +		warning("could not mark '%s' as hidden.", filename);
  	return file;
  }
  

-- 
2.8.2.463.g99156ee

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]