@@ -52,7 +52,24 @@ struct config_source {
52
52
#define CONFIG_SOURCE_INIT { 0 }
53
53
54
54
struct config_reader {
55
+ /*
56
+ * These members record the "current" config source, which can be
57
+ * accessed by parsing callbacks.
58
+ *
59
+ * The "source" variable will be non-NULL only when we are actually
60
+ * parsing a real config source (file, blob, cmdline, etc).
61
+ *
62
+ * The "config_kvi" variable will be non-NULL only when we are feeding
63
+ * cached config from a configset into a callback.
64
+ *
65
+ * They cannot be non-NULL at the same time. If they are both NULL, then
66
+ * we aren't parsing anything (and depending on the function looking at
67
+ * the variables, it's either a bug for it to be called in the first
68
+ * place, or it's a function which can be reused for non-config
69
+ * purposes, and should fall back to some sane behavior).
70
+ */
55
71
struct config_source * source ;
72
+ struct key_value_info * config_kvi ;
56
73
};
57
74
/*
58
75
* Where possible, prefer to accept "struct config_reader" as an arg than to use
@@ -61,27 +78,6 @@ struct config_reader {
61
78
*/
62
79
static struct config_reader the_reader ;
63
80
64
- /*
65
- * FIXME The comments are temporarily out of date since "cf_global" has been
66
- * moved to the_reader, but not current_*.
67
- *
68
- * These variables record the "current" config source, which
69
- * can be accessed by parsing callbacks.
70
- *
71
- * The "cf_global" variable will be non-NULL only when we are actually
72
- * parsing a real config source (file, blob, cmdline, etc).
73
- *
74
- * The "current_config_kvi" variable will be non-NULL only when we are feeding
75
- * cached config from a configset into a callback.
76
- *
77
- * They should generally never be non-NULL at the same time. If they are both
78
- * NULL, then we aren't parsing anything (and depending on the function looking
79
- * at the variables, it's either a bug for it to be called in the first place,
80
- * or it's a function which can be reused for non-config purposes, and should
81
- * fall back to some sane behavior).
82
- */
83
- static struct key_value_info * current_config_kvi ;
84
-
85
81
/*
86
82
* Similar to the variables above, this gives access to the "scope" of the
87
83
* current value (repo, global, etc). For cached values, it can be found via
@@ -95,6 +91,8 @@ static enum config_scope current_parsing_scope;
95
91
static inline void config_reader_push_source (struct config_reader * reader ,
96
92
struct config_source * top )
97
93
{
94
+ if (reader -> config_kvi )
95
+ BUG ("source should not be set while iterating a config set" );
98
96
top -> prev = reader -> source ;
99
97
reader -> source = top ;
100
98
}
@@ -109,6 +107,14 @@ static inline struct config_source *config_reader_pop_source(struct config_reade
109
107
return ret ;
110
108
}
111
109
110
+ static inline void config_reader_set_kvi (struct config_reader * reader ,
111
+ struct key_value_info * kvi )
112
+ {
113
+ if (kvi && reader -> source )
114
+ BUG ("kvi should not be set while parsing a config source" );
115
+ reader -> config_kvi = kvi ;
116
+ }
117
+
112
118
static int pack_compression_seen ;
113
119
static int zlib_compression_seen ;
114
120
@@ -377,20 +383,17 @@ static void populate_remote_urls(struct config_include_data *inc)
377
383
{
378
384
struct config_options opts ;
379
385
380
- struct key_value_info * store_kvi = current_config_kvi ;
381
386
enum config_scope store_scope = current_parsing_scope ;
382
387
383
388
opts = * inc -> opts ;
384
389
opts .unconditional_remote_url = 1 ;
385
390
386
- current_config_kvi = NULL ;
387
391
current_parsing_scope = 0 ;
388
392
389
393
inc -> remote_urls = xmalloc (sizeof (* inc -> remote_urls ));
390
394
string_list_init_dup (inc -> remote_urls );
391
395
config_with_options (add_remote_url , inc -> remote_urls , inc -> config_source , & opts );
392
396
393
- current_config_kvi = store_kvi ;
394
397
current_parsing_scope = store_scope ;
395
398
}
396
399
@@ -2257,7 +2260,8 @@ int config_with_options(config_fn_t fn, void *data,
2257
2260
return ret ;
2258
2261
}
2259
2262
2260
- static void configset_iter (struct config_set * cs , config_fn_t fn , void * data )
2263
+ static void configset_iter (struct config_reader * reader , struct config_set * cs ,
2264
+ config_fn_t fn , void * data )
2261
2265
{
2262
2266
int i , value_index ;
2263
2267
struct string_list * values ;
@@ -2269,14 +2273,14 @@ static void configset_iter(struct config_set *cs, config_fn_t fn, void *data)
2269
2273
value_index = list -> items [i ].value_index ;
2270
2274
values = & entry -> value_list ;
2271
2275
2272
- current_config_kvi = values -> items [value_index ].util ;
2276
+ config_reader_set_kvi ( reader , values -> items [value_index ].util ) ;
2273
2277
2274
2278
if (fn (entry -> key , values -> items [value_index ].string , data ) < 0 )
2275
2279
git_die_config_linenr (entry -> key ,
2276
- current_config_kvi -> filename ,
2277
- current_config_kvi -> linenr );
2280
+ reader -> config_kvi -> filename ,
2281
+ reader -> config_kvi -> linenr );
2278
2282
2279
- current_config_kvi = NULL ;
2283
+ config_reader_set_kvi ( reader , NULL ) ;
2280
2284
}
2281
2285
}
2282
2286
@@ -2614,7 +2618,7 @@ static void repo_config_clear(struct repository *repo)
2614
2618
void repo_config (struct repository * repo , config_fn_t fn , void * data )
2615
2619
{
2616
2620
git_config_check_init (repo );
2617
- configset_iter (repo -> config , fn , data );
2621
+ configset_iter (& the_reader , repo -> config , fn , data );
2618
2622
}
2619
2623
2620
2624
int repo_config_get_value (struct repository * repo ,
@@ -2720,7 +2724,7 @@ void git_protected_config(config_fn_t fn, void *data)
2720
2724
{
2721
2725
if (!protected_config .hash_initialized )
2722
2726
read_protected_config ();
2723
- configset_iter (& protected_config , fn , data );
2727
+ configset_iter (& the_reader , & protected_config , fn , data );
2724
2728
}
2725
2729
2726
2730
/* Functions used historically to read configuration from 'the_repository' */
@@ -3827,8 +3831,8 @@ int parse_config_key(const char *var,
3827
3831
const char * current_config_origin_type (void )
3828
3832
{
3829
3833
int type ;
3830
- if (current_config_kvi )
3831
- type = current_config_kvi -> origin_type ;
3834
+ if (the_reader . config_kvi )
3835
+ type = the_reader . config_kvi -> origin_type ;
3832
3836
else if (the_reader .source )
3833
3837
type = the_reader .source -> origin_type ;
3834
3838
else
@@ -3873,8 +3877,8 @@ const char *config_scope_name(enum config_scope scope)
3873
3877
const char * current_config_name (void )
3874
3878
{
3875
3879
const char * name ;
3876
- if (current_config_kvi )
3877
- name = current_config_kvi -> filename ;
3880
+ if (the_reader . config_kvi )
3881
+ name = the_reader . config_kvi -> filename ;
3878
3882
else if (the_reader .source )
3879
3883
name = the_reader .source -> name ;
3880
3884
else
@@ -3884,16 +3888,16 @@ const char *current_config_name(void)
3884
3888
3885
3889
enum config_scope current_config_scope (void )
3886
3890
{
3887
- if (current_config_kvi )
3888
- return current_config_kvi -> scope ;
3891
+ if (the_reader . config_kvi )
3892
+ return the_reader . config_kvi -> scope ;
3889
3893
else
3890
3894
return current_parsing_scope ;
3891
3895
}
3892
3896
3893
3897
int current_config_line (void )
3894
3898
{
3895
- if (current_config_kvi )
3896
- return current_config_kvi -> linenr ;
3899
+ if (the_reader . config_kvi )
3900
+ return the_reader . config_kvi -> linenr ;
3897
3901
else
3898
3902
return the_reader .source -> linenr ;
3899
3903
}
0 commit comments