Skip to content

Commit 551d75d

Browse files
committed
Merge branch 'rj/config-cygwin'
* rj/config-cygwin: config.c: Make git_config() work correctly when called recursively t1301-*.sh: Fix the 'forced modes' test on cygwin help.c: Fix detection of custom merge strategy on cygwin
2 parents bc50897 + 924aaf3 commit 551d75d

File tree

3 files changed

+55
-33
lines changed

3 files changed

+55
-33
lines changed

compat/cygwin.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ static int git_cygwin_config(const char *var, const char *value, void *cb)
114114

115115
static int init_stat(void)
116116
{
117-
if (have_git_dir()) {
118-
git_config(git_cygwin_config, NULL);
117+
if (have_git_dir() && git_config(git_cygwin_config,NULL)) {
119118
if (!core_filemode && native_stat) {
120119
cygwin_stat_fn = cygwin_stat;
121120
cygwin_lstat_fn = cygwin_lstat;

config.c

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@
1212

1313
#define MAXNAME (256)
1414

15-
static FILE *config_file;
16-
static const char *config_file_name;
17-
static int config_linenr;
18-
static int config_file_eof;
15+
typedef struct config_file {
16+
struct config_file *prev;
17+
FILE *f;
18+
const char *name;
19+
int linenr;
20+
int eof;
21+
struct strbuf value;
22+
char var[MAXNAME];
23+
} config_file;
24+
25+
static config_file *cf;
26+
1927
static int zlib_compression_seen;
2028

2129
const char *config_exclusive_filename = NULL;
@@ -99,7 +107,7 @@ static int get_next_char(void)
99107
FILE *f;
100108

101109
c = '\n';
102-
if ((f = config_file) != NULL) {
110+
if (cf && ((f = cf->f) != NULL)) {
103111
c = fgetc(f);
104112
if (c == '\r') {
105113
/* DOS like systems */
@@ -110,9 +118,9 @@ static int get_next_char(void)
110118
}
111119
}
112120
if (c == '\n')
113-
config_linenr++;
121+
cf->linenr++;
114122
if (c == EOF) {
115-
config_file_eof = 1;
123+
cf->eof = 1;
116124
c = '\n';
117125
}
118126
}
@@ -121,21 +129,20 @@ static int get_next_char(void)
121129

122130
static char *parse_value(void)
123131
{
124-
static struct strbuf value = STRBUF_INIT;
125132
int quote = 0, comment = 0, space = 0;
126133

127-
strbuf_reset(&value);
134+
strbuf_reset(&cf->value);
128135
for (;;) {
129136
int c = get_next_char();
130137
if (c == '\n') {
131138
if (quote)
132139
return NULL;
133-
return value.buf;
140+
return cf->value.buf;
134141
}
135142
if (comment)
136143
continue;
137144
if (isspace(c) && !quote) {
138-
if (value.len)
145+
if (cf->value.len)
139146
space++;
140147
continue;
141148
}
@@ -146,7 +153,7 @@ static char *parse_value(void)
146153
}
147154
}
148155
for (; space; space--)
149-
strbuf_addch(&value, ' ');
156+
strbuf_addch(&cf->value, ' ');
150157
if (c == '\\') {
151158
c = get_next_char();
152159
switch (c) {
@@ -168,14 +175,14 @@ static char *parse_value(void)
168175
default:
169176
return NULL;
170177
}
171-
strbuf_addch(&value, c);
178+
strbuf_addch(&cf->value, c);
172179
continue;
173180
}
174181
if (c == '"') {
175182
quote = 1-quote;
176183
continue;
177184
}
178-
strbuf_addch(&value, c);
185+
strbuf_addch(&cf->value, c);
179186
}
180187
}
181188

@@ -192,7 +199,7 @@ static int get_value(config_fn_t fn, void *data, char *name, unsigned int len)
192199
/* Get the full name */
193200
for (;;) {
194201
c = get_next_char();
195-
if (config_file_eof)
202+
if (cf->eof)
196203
break;
197204
if (!iskeychar(c))
198205
break;
@@ -256,7 +263,7 @@ static int get_base_var(char *name)
256263

257264
for (;;) {
258265
int c = get_next_char();
259-
if (config_file_eof)
266+
if (cf->eof)
260267
return -1;
261268
if (c == ']')
262269
return baselen;
@@ -274,7 +281,7 @@ static int git_parse_file(config_fn_t fn, void *data)
274281
{
275282
int comment = 0;
276283
int baselen = 0;
277-
static char var[MAXNAME];
284+
char *var = cf->var;
278285

279286
/* U+FEFF Byte Order Mark in UTF8 */
280287
static const unsigned char *utf8_bom = (unsigned char *) "\xef\xbb\xbf";
@@ -298,7 +305,7 @@ static int git_parse_file(config_fn_t fn, void *data)
298305
}
299306
}
300307
if (c == '\n') {
301-
if (config_file_eof)
308+
if (cf->eof)
302309
return 0;
303310
comment = 0;
304311
continue;
@@ -323,7 +330,7 @@ static int git_parse_file(config_fn_t fn, void *data)
323330
if (get_value(fn, data, var, baselen+1) < 0)
324331
break;
325332
}
326-
die("bad config file line %d in %s", config_linenr, config_file_name);
333+
die("bad config file line %d in %s", cf->linenr, cf->name);
327334
}
328335

329336
static int parse_unit_factor(const char *end, unsigned long *val)
@@ -374,8 +381,8 @@ int git_parse_ulong(const char *value, unsigned long *ret)
374381

375382
static void die_bad_config(const char *name)
376383
{
377-
if (config_file_name)
378-
die("bad config value for '%s' in %s", name, config_file_name);
384+
if (cf && cf->name)
385+
die("bad config value for '%s' in %s", name, cf->name);
379386
die("bad config value for '%s'", name);
380387
}
381388

@@ -795,13 +802,24 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
795802

796803
ret = -1;
797804
if (f) {
798-
config_file = f;
799-
config_file_name = filename;
800-
config_linenr = 1;
801-
config_file_eof = 0;
805+
config_file top;
806+
807+
/* push config-file parsing state stack */
808+
top.prev = cf;
809+
top.f = f;
810+
top.name = filename;
811+
top.linenr = 1;
812+
top.eof = 0;
813+
strbuf_init(&top.value, 1024);
814+
cf = &top;
815+
802816
ret = git_parse_file(fn, data);
817+
818+
/* pop config-file parsing state stack */
819+
strbuf_release(&top.value);
820+
cf = top.prev;
821+
803822
fclose(f);
804-
config_file_name = NULL;
805823
}
806824
return ret;
807825
}
@@ -909,6 +927,7 @@ static int store_aux(const char *key, const char *value, void *cb)
909927
{
910928
const char *ep;
911929
size_t section_len;
930+
FILE *f = cf->f;
912931

913932
switch (store.state) {
914933
case KEY_SEEN:
@@ -920,7 +939,7 @@ static int store_aux(const char *key, const char *value, void *cb)
920939
return 1;
921940
}
922941

923-
store.offset[store.seen] = ftell(config_file);
942+
store.offset[store.seen] = ftell(f);
924943
store.seen++;
925944
}
926945
break;
@@ -947,19 +966,19 @@ static int store_aux(const char *key, const char *value, void *cb)
947966
* Do not increment matches: this is no match, but we
948967
* just made sure we are in the desired section.
949968
*/
950-
store.offset[store.seen] = ftell(config_file);
969+
store.offset[store.seen] = ftell(f);
951970
/* fallthru */
952971
case SECTION_END_SEEN:
953972
case START:
954973
if (matches(key, value)) {
955-
store.offset[store.seen] = ftell(config_file);
974+
store.offset[store.seen] = ftell(f);
956975
store.state = KEY_SEEN;
957976
store.seen++;
958977
} else {
959978
if (strrchr(key, '.') - key == store.baselen &&
960979
!strncmp(key, store.key, store.baselen)) {
961980
store.state = SECTION_SEEN;
962-
store.offset[store.seen] = ftell(config_file);
981+
store.offset[store.seen] = ftell(f);
963982
}
964983
}
965984
}
@@ -1415,6 +1434,7 @@ int git_config_rename_section(const char *old_name, const char *new_name)
14151434
struct lock_file *lock = xcalloc(sizeof(struct lock_file), 1);
14161435
int out_fd;
14171436
char buf[1024];
1437+
FILE *config_file;
14181438

14191439
if (config_exclusive_filename)
14201440
config_filename = xstrdup(config_exclusive_filename);

help.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ static int is_executable(const char *name)
127127
!S_ISREG(st.st_mode))
128128
return 0;
129129

130-
#ifdef WIN32
130+
#if defined(WIN32) || defined(__CYGWIN__)
131+
#if defined(__CYGWIN__)
132+
if ((st.st_mode & S_IXUSR) == 0)
133+
#endif
131134
{ /* cannot trust the executable bit, peek into the file instead */
132135
char buf[3] = { 0 };
133136
int n;

0 commit comments

Comments
 (0)