Skip to content

Commit 7faee6b

Browse files
mark987gitster
authored andcommitted
compat/cygwin.c - Use cygwin's stat if core.filemode == true
Cygwin's POSIX emulation allows use of core.filemode true, unlike native Window's implementation of stat / lstat, and Cygwin/git users who have configured core.filemode true in various repositories will be very unpleasantly surprised to find that git is no longer honoring that option. So, this patch forces use of Cygwin's stat functions if core.filemode is set true, regardless of any other considerations. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5c283eb commit 7faee6b

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Documentation/config.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ core.ignoreCygwinFSTricks::
124124
one hierarchy using Cygwin mount. If true, Git uses native Win32 API
125125
whenever it is possible and falls back to Cygwin functions only to
126126
handle symbol links. The native mode is more than twice faster than
127-
normal Cygwin l/stat() functions. True by default.
127+
normal Cygwin l/stat() functions. True by default, unless core.filemode
128+
is true, in which case ignoreCygwinFSTricks is ignored as Cygwin's
129+
POSIX emulation is required to support core.filemode.
128130

129131
core.trustctime::
130132
If false, the ctime differences between the index and the

compat/cygwin.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,32 @@ static int cygwin_stat(const char *path, struct stat *buf)
9191
* functions should be used. The choice is determined by core.ignorecygwinfstricks.
9292
* Reading this option is not always possible immediately as git_dir may be
9393
* not be set yet. So until it is set, use cygwin lstat/stat functions.
94+
* However, if the trust_executable_bit is set, we must use the Cygwin posix
95+
* stat/lstat as the Windows stat fuctions do not determine posix filemode.
9496
*/
9597
static int native_stat = 1;
98+
extern int trust_executable_bit;
9699

97100
static int git_cygwin_config(const char *var, const char *value, void *cb)
98101
{
99-
if (!strcmp(var, "core.ignorecygwinfstricks"))
102+
if (!strcmp(var, "core.ignorecygwinfstricks")) {
100103
native_stat = git_config_bool(var, value);
101-
return 0;
104+
return 0;
105+
}
106+
return git_default_config(var, value, cb);
102107
}
103108

104109
static int init_stat(void)
105110
{
106111
if (have_git_dir()) {
107112
git_config(git_cygwin_config, NULL);
108-
cygwin_stat_fn = native_stat ? cygwin_stat : stat;
109-
cygwin_lstat_fn = native_stat ? cygwin_lstat : lstat;
113+
if (!trust_executable_bit && native_stat) {
114+
cygwin_stat_fn = cygwin_stat;
115+
cygwin_lstat_fn = cygwin_lstat;
116+
} else {
117+
cygwin_stat_fn = stat;
118+
cygwin_lstat_fn = lstat;
119+
}
110120
return 0;
111121
}
112122
return 1;

0 commit comments

Comments
 (0)