Skip to content

Commit 7974843

Browse files
committed
compat/cygwin.c: make runtime detection of lstat/stat lessor impact
The original patch that lead to an earlier commit adbc0b6 (cygwin: Use native Win32 API for stat, 2008-09-30) did not call git_default_config() and it was a good thing. The lazy config reading when lstat/stat is called for the first time to find out if core.filemode is set can happen anytime in the calling program. If it happens after the calling program parsed the configuration file to prime its default parameter settings and processed its command line parameters to tweak them, this will overwrite the values set by the program with the values read from the config file. This essentially reverts the code to the version as submitted by Mark, with a bit more comments to clarify why we do not fall back on the default configuration parser from git_cygwin_config(). Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 304d058 commit 7974843

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

compat/cygwin.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +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
94+
* However, if core.filemode is set, we must use the Cygwin posix
9595
* stat/lstat as the Windows stat fuctions do not determine posix filemode.
96+
*
97+
* Note that git_cygwin_config() does NOT call git_default_config() and this
98+
* is deliberate. Many commands read from config to establish initial
99+
* values in variables and later tweak them from elsewhere (e.g. command line).
100+
* init_stat() is called lazily on demand, typically much late in the program,
101+
* and calling git_default_config() from here would break such variables.
96102
*/
97103
static int native_stat = 1;
98-
extern int trust_executable_bit;
104+
static int core_filemode;
99105

100106
static int git_cygwin_config(const char *var, const char *value, void *cb)
101107
{
102-
if (!strcmp(var, "core.ignorecygwinfstricks")) {
108+
if (!strcmp(var, "core.ignorecygwinfstricks"))
103109
native_stat = git_config_bool(var, value);
104-
return 0;
105-
}
106-
return git_default_config(var, value, cb);
110+
else if (!strcmp(var, "core.filemode"))
111+
core_filemode = git_config_bool(var, value);
112+
return 0;
107113
}
108114

109115
static int init_stat(void)
110116
{
111117
if (have_git_dir()) {
112118
git_config(git_cygwin_config, NULL);
113-
if (!trust_executable_bit && native_stat) {
119+
if (!core_filemode && native_stat) {
114120
cygwin_stat_fn = cygwin_stat;
115121
cygwin_lstat_fn = cygwin_lstat;
116122
} else {

0 commit comments

Comments
 (0)