@@ -70,6 +70,16 @@ struct config_reader {
70
70
*/
71
71
struct config_source * source ;
72
72
struct key_value_info * config_kvi ;
73
+ /*
74
+ * The "scope" of the current config source being parsed (repo, global,
75
+ * etc). Like "source", this is only set when parsing a config source.
76
+ * It's not part of "source" because it transcends a single file (i.e.,
77
+ * a file included from .git/config is still in "repo" scope).
78
+ *
79
+ * When iterating through a configset, the equivalent value is
80
+ * "config_kvi.scope" (see above).
81
+ */
82
+ enum config_scope parsing_scope ;
73
83
};
74
84
/*
75
85
* Where possible, prefer to accept "struct config_reader" as an arg than to use
@@ -78,16 +88,6 @@ struct config_reader {
78
88
*/
79
89
static struct config_reader the_reader ;
80
90
81
- /*
82
- * Similar to the variables above, this gives access to the "scope" of the
83
- * current value (repo, global, etc). For cached values, it can be found via
84
- * the current_config_kvi as above. During parsing, the current value can be
85
- * found in this variable. It's not part of "cf_global" because it transcends a
86
- * single file (i.e., a file included from .git/config is still in "repo"
87
- * scope).
88
- */
89
- static enum config_scope current_parsing_scope ;
90
-
91
91
static inline void config_reader_push_source (struct config_reader * reader ,
92
92
struct config_source * top )
93
93
{
@@ -110,11 +110,19 @@ static inline struct config_source *config_reader_pop_source(struct config_reade
110
110
static inline void config_reader_set_kvi (struct config_reader * reader ,
111
111
struct key_value_info * kvi )
112
112
{
113
- if (kvi && reader -> source )
113
+ if (kvi && ( reader -> source || reader -> parsing_scope ) )
114
114
BUG ("kvi should not be set while parsing a config source" );
115
115
reader -> config_kvi = kvi ;
116
116
}
117
117
118
+ static inline void config_reader_set_scope (struct config_reader * reader ,
119
+ enum config_scope scope )
120
+ {
121
+ if (scope && reader -> config_kvi )
122
+ BUG ("scope should only be set when iterating through a config source" );
123
+ reader -> parsing_scope = scope ;
124
+ }
125
+
118
126
static int pack_compression_seen ;
119
127
static int zlib_compression_seen ;
120
128
@@ -383,18 +391,18 @@ static void populate_remote_urls(struct config_include_data *inc)
383
391
{
384
392
struct config_options opts ;
385
393
386
- enum config_scope store_scope = current_parsing_scope ;
394
+ enum config_scope store_scope = inc -> config_reader -> parsing_scope ;
387
395
388
396
opts = * inc -> opts ;
389
397
opts .unconditional_remote_url = 1 ;
390
398
391
- current_parsing_scope = 0 ;
399
+ config_reader_set_scope ( inc -> config_reader , 0 ) ;
392
400
393
401
inc -> remote_urls = xmalloc (sizeof (* inc -> remote_urls ));
394
402
string_list_init_dup (inc -> remote_urls );
395
403
config_with_options (add_remote_url , inc -> remote_urls , inc -> config_source , & opts );
396
404
397
- current_parsing_scope = store_scope ;
405
+ config_reader_set_scope ( inc -> config_reader , store_scope ) ;
398
406
}
399
407
400
408
static int forbid_remote_url (const char * var , const char * value UNUSED ,
@@ -2159,15 +2167,16 @@ int git_config_system(void)
2159
2167
return !git_env_bool ("GIT_CONFIG_NOSYSTEM" , 0 );
2160
2168
}
2161
2169
2162
- static int do_git_config_sequence (const struct config_options * opts ,
2170
+ static int do_git_config_sequence (struct config_reader * reader ,
2171
+ const struct config_options * opts ,
2163
2172
config_fn_t fn , void * data )
2164
2173
{
2165
2174
int ret = 0 ;
2166
2175
char * system_config = git_system_config ();
2167
2176
char * xdg_config = NULL ;
2168
2177
char * user_config = NULL ;
2169
2178
char * repo_config ;
2170
- enum config_scope prev_parsing_scope = current_parsing_scope ;
2179
+ enum config_scope prev_parsing_scope = reader -> parsing_scope ;
2171
2180
2172
2181
if (opts -> commondir )
2173
2182
repo_config = mkpathdup ("%s/config" , opts -> commondir );
@@ -2176,13 +2185,13 @@ static int do_git_config_sequence(const struct config_options *opts,
2176
2185
else
2177
2186
repo_config = NULL ;
2178
2187
2179
- current_parsing_scope = CONFIG_SCOPE_SYSTEM ;
2188
+ config_reader_set_scope ( reader , CONFIG_SCOPE_SYSTEM ) ;
2180
2189
if (git_config_system () && system_config &&
2181
2190
!access_or_die (system_config , R_OK ,
2182
2191
opts -> system_gently ? ACCESS_EACCES_OK : 0 ))
2183
2192
ret += git_config_from_file (fn , system_config , data );
2184
2193
2185
- current_parsing_scope = CONFIG_SCOPE_GLOBAL ;
2194
+ config_reader_set_scope ( reader , CONFIG_SCOPE_GLOBAL ) ;
2186
2195
git_global_config (& user_config , & xdg_config );
2187
2196
2188
2197
if (xdg_config && !access_or_die (xdg_config , R_OK , ACCESS_EACCES_OK ))
@@ -2191,24 +2200,24 @@ static int do_git_config_sequence(const struct config_options *opts,
2191
2200
if (user_config && !access_or_die (user_config , R_OK , ACCESS_EACCES_OK ))
2192
2201
ret += git_config_from_file (fn , user_config , data );
2193
2202
2194
- current_parsing_scope = CONFIG_SCOPE_LOCAL ;
2203
+ config_reader_set_scope ( reader , CONFIG_SCOPE_LOCAL ) ;
2195
2204
if (!opts -> ignore_repo && repo_config &&
2196
2205
!access_or_die (repo_config , R_OK , 0 ))
2197
2206
ret += git_config_from_file (fn , repo_config , data );
2198
2207
2199
- current_parsing_scope = CONFIG_SCOPE_WORKTREE ;
2208
+ config_reader_set_scope ( reader , CONFIG_SCOPE_WORKTREE ) ;
2200
2209
if (!opts -> ignore_worktree && repository_format_worktree_config ) {
2201
2210
char * path = git_pathdup ("config.worktree" );
2202
2211
if (!access_or_die (path , R_OK , 0 ))
2203
2212
ret += git_config_from_file (fn , path , data );
2204
2213
free (path );
2205
2214
}
2206
2215
2207
- current_parsing_scope = CONFIG_SCOPE_COMMAND ;
2216
+ config_reader_set_scope ( reader , CONFIG_SCOPE_COMMAND ) ;
2208
2217
if (!opts -> ignore_cmdline && git_config_from_parameters (fn , data ) < 0 )
2209
2218
die (_ ("unable to parse command-line config" ));
2210
2219
2211
- current_parsing_scope = prev_parsing_scope ;
2220
+ config_reader_set_scope ( reader , prev_parsing_scope ) ;
2212
2221
free (system_config );
2213
2222
free (xdg_config );
2214
2223
free (user_config );
@@ -2221,6 +2230,7 @@ int config_with_options(config_fn_t fn, void *data,
2221
2230
const struct config_options * opts )
2222
2231
{
2223
2232
struct config_include_data inc = CONFIG_INCLUDE_INIT ;
2233
+ enum config_scope prev_scope = the_reader .parsing_scope ;
2224
2234
int ret ;
2225
2235
2226
2236
if (opts -> respect_includes ) {
@@ -2234,7 +2244,7 @@ int config_with_options(config_fn_t fn, void *data,
2234
2244
}
2235
2245
2236
2246
if (config_source )
2237
- current_parsing_scope = config_source -> scope ;
2247
+ config_reader_set_scope ( & the_reader , config_source -> scope ) ;
2238
2248
2239
2249
/*
2240
2250
* If we have a specific filename, use it. Otherwise, follow the
@@ -2250,13 +2260,14 @@ int config_with_options(config_fn_t fn, void *data,
2250
2260
ret = git_config_from_blob_ref (fn , repo , config_source -> blob ,
2251
2261
data );
2252
2262
} else {
2253
- ret = do_git_config_sequence (opts , fn , data );
2263
+ ret = do_git_config_sequence (& the_reader , opts , fn , data );
2254
2264
}
2255
2265
2256
2266
if (inc .remote_urls ) {
2257
2267
string_list_clear (inc .remote_urls , 0 );
2258
2268
FREE_AND_NULL (inc .remote_urls );
2259
2269
}
2270
+ config_reader_set_scope (& the_reader , prev_scope );
2260
2271
return ret ;
2261
2272
}
2262
2273
@@ -2390,7 +2401,7 @@ static int configset_add_value(struct config_reader *reader,
2390
2401
kv_info -> linenr = -1 ;
2391
2402
kv_info -> origin_type = CONFIG_ORIGIN_CMDLINE ;
2392
2403
}
2393
- kv_info -> scope = current_parsing_scope ;
2404
+ kv_info -> scope = reader -> parsing_scope ;
2394
2405
si -> util = kv_info ;
2395
2406
2396
2407
return 0 ;
@@ -3891,7 +3902,7 @@ enum config_scope current_config_scope(void)
3891
3902
if (the_reader .config_kvi )
3892
3903
return the_reader .config_kvi -> scope ;
3893
3904
else
3894
- return current_parsing_scope ;
3905
+ return the_reader . parsing_scope ;
3895
3906
}
3896
3907
3897
3908
int current_config_line (void )
0 commit comments