@@ -66,40 +66,6 @@ struct config_source {
66
66
};
67
67
#define CONFIG_SOURCE_INIT { 0 }
68
68
69
- struct config_reader {
70
- /*
71
- * These members record the "current" config source, which can be
72
- * accessed by parsing callbacks.
73
- *
74
- * The "source" variable will be non-NULL only when we are actually
75
- * parsing a real config source (file, blob, cmdline, etc).
76
- */
77
- struct config_source * source ;
78
- };
79
- /*
80
- * Where possible, prefer to accept "struct config_reader" as an arg than to use
81
- * "the_reader". "the_reader" should only be used if that is infeasible, e.g. in
82
- * a public function.
83
- */
84
- static struct config_reader the_reader ;
85
-
86
- static inline void config_reader_push_source (struct config_reader * reader ,
87
- struct config_source * top )
88
- {
89
- top -> prev = reader -> source ;
90
- reader -> source = top ;
91
- }
92
-
93
- static inline struct config_source * config_reader_pop_source (struct config_reader * reader )
94
- {
95
- struct config_source * ret ;
96
- if (!reader -> source )
97
- BUG ("tried to pop config source, but we weren't reading config" );
98
- ret = reader -> source ;
99
- reader -> source = reader -> source -> prev ;
100
- return ret ;
101
- }
102
-
103
69
static int pack_compression_seen ;
104
70
static int zlib_compression_seen ;
105
71
@@ -752,14 +718,9 @@ int git_config_from_parameters(config_fn_t fn, void *data)
752
718
struct strvec to_free = STRVEC_INIT ;
753
719
int ret = 0 ;
754
720
char * envw = NULL ;
755
- struct config_source source = CONFIG_SOURCE_INIT ;
756
721
struct key_value_info kvi = KVI_INIT ;
757
722
758
- source .origin_type = CONFIG_ORIGIN_CMDLINE ;
759
- config_reader_push_source (& the_reader , & source );
760
-
761
723
kvi_from_param (& kvi );
762
-
763
724
env = getenv (CONFIG_COUNT_ENVIRONMENT );
764
725
if (env ) {
765
726
unsigned long count ;
@@ -816,7 +777,6 @@ int git_config_from_parameters(config_fn_t fn, void *data)
816
777
strbuf_release (& envvar );
817
778
strvec_clear (& to_free );
818
779
free (envw );
819
- config_reader_pop_source (& the_reader );
820
780
return ret ;
821
781
}
822
782
@@ -1045,7 +1005,7 @@ static int do_event(struct config_source *cs, enum config_event_t type,
1045
1005
1046
1006
if (data -> previous_type != CONFIG_EVENT_EOF &&
1047
1007
data -> opts -> event_fn (data -> previous_type , data -> previous_offset ,
1048
- offset , data -> opts -> event_fn_data ) < 0 )
1008
+ offset , cs , data -> opts -> event_fn_data ) < 0 )
1049
1009
return -1 ;
1050
1010
1051
1011
data -> previous_type = type ;
@@ -2002,8 +1962,7 @@ int git_default_config(const char *var, const char *value,
2002
1962
* fgetc, ungetc, ftell of top need to be initialized before calling
2003
1963
* this function.
2004
1964
*/
2005
- static int do_config_from (struct config_reader * reader ,
2006
- struct config_source * top , config_fn_t fn ,
1965
+ static int do_config_from (struct config_source * top , config_fn_t fn ,
2007
1966
void * data , enum config_scope scope ,
2008
1967
const struct config_options * opts )
2009
1968
{
@@ -2016,21 +1975,17 @@ static int do_config_from(struct config_reader *reader,
2016
1975
top -> total_len = 0 ;
2017
1976
strbuf_init (& top -> value , 1024 );
2018
1977
strbuf_init (& top -> var , 1024 );
2019
- config_reader_push_source (reader , top );
2020
1978
kvi_from_source (top , scope , & kvi );
2021
1979
2022
1980
ret = git_parse_source (top , fn , & kvi , data , opts );
2023
1981
2024
- /* pop config-file parsing state stack */
2025
1982
strbuf_release (& top -> value );
2026
1983
strbuf_release (& top -> var );
2027
- config_reader_pop_source (reader );
2028
1984
2029
1985
return ret ;
2030
1986
}
2031
1987
2032
- static int do_config_from_file (struct config_reader * reader ,
2033
- config_fn_t fn ,
1988
+ static int do_config_from_file (config_fn_t fn ,
2034
1989
const enum config_origin_type origin_type ,
2035
1990
const char * name , const char * path , FILE * f ,
2036
1991
void * data , enum config_scope scope ,
@@ -2049,16 +2004,16 @@ static int do_config_from_file(struct config_reader *reader,
2049
2004
top .do_ftell = config_file_ftell ;
2050
2005
2051
2006
flockfile (f );
2052
- ret = do_config_from (reader , & top , fn , data , scope , opts );
2007
+ ret = do_config_from (& top , fn , data , scope , opts );
2053
2008
funlockfile (f );
2054
2009
return ret ;
2055
2010
}
2056
2011
2057
2012
static int git_config_from_stdin (config_fn_t fn , void * data ,
2058
2013
enum config_scope scope )
2059
2014
{
2060
- return do_config_from_file (& the_reader , fn , CONFIG_ORIGIN_STDIN , "" ,
2061
- NULL , stdin , data , scope , NULL );
2015
+ return do_config_from_file (fn , CONFIG_ORIGIN_STDIN , "" , NULL , stdin ,
2016
+ data , scope , NULL );
2062
2017
}
2063
2018
2064
2019
int git_config_from_file_with_options (config_fn_t fn , const char * filename ,
@@ -2072,9 +2027,8 @@ int git_config_from_file_with_options(config_fn_t fn, const char *filename,
2072
2027
BUG ("filename cannot be NULL" );
2073
2028
f = fopen_or_warn (filename , "r" );
2074
2029
if (f ) {
2075
- ret = do_config_from_file (& the_reader , fn , CONFIG_ORIGIN_FILE ,
2076
- filename , filename , f , data , scope ,
2077
- opts );
2030
+ ret = do_config_from_file (fn , CONFIG_ORIGIN_FILE , filename ,
2031
+ filename , f , data , scope , opts );
2078
2032
fclose (f );
2079
2033
}
2080
2034
return ret ;
@@ -2105,7 +2059,7 @@ int git_config_from_mem(config_fn_t fn,
2105
2059
top .do_ungetc = config_buf_ungetc ;
2106
2060
top .do_ftell = config_buf_ftell ;
2107
2061
2108
- return do_config_from (& the_reader , & top , fn , data , scope , opts );
2062
+ return do_config_from (& top , fn , data , scope , opts );
2109
2063
}
2110
2064
2111
2065
int git_config_from_blob_oid (config_fn_t fn ,
@@ -2198,8 +2152,7 @@ int git_config_system(void)
2198
2152
return !git_env_bool ("GIT_CONFIG_NOSYSTEM" , 0 );
2199
2153
}
2200
2154
2201
- static int do_git_config_sequence (struct config_reader * reader ,
2202
- const struct config_options * opts ,
2155
+ static int do_git_config_sequence (const struct config_options * opts ,
2203
2156
const struct repository * repo ,
2204
2157
config_fn_t fn , void * data )
2205
2158
{
@@ -2299,7 +2252,7 @@ int config_with_options(config_fn_t fn, void *data,
2299
2252
ret = git_config_from_blob_ref (fn , repo , config_source -> blob ,
2300
2253
data , config_source -> scope );
2301
2254
} else {
2302
- ret = do_git_config_sequence (& the_reader , opts , repo , fn , data );
2255
+ ret = do_git_config_sequence (opts , repo , fn , data );
2303
2256
}
2304
2257
2305
2258
if (inc .remote_urls ) {
@@ -3009,7 +2962,6 @@ void git_die_config(const char *key, const char *err, ...)
3009
2962
*/
3010
2963
3011
2964
struct config_store_data {
3012
- struct config_reader * config_reader ;
3013
2965
size_t baselen ;
3014
2966
char * key ;
3015
2967
int do_not_match ;
@@ -3055,11 +3007,10 @@ static int matches(const char *key, const char *value,
3055
3007
(value && !regexec (store -> value_pattern , value , 0 , NULL , 0 ));
3056
3008
}
3057
3009
3058
- static int store_aux_event (enum config_event_t type ,
3059
- size_t begin , size_t end , void * data )
3010
+ static int store_aux_event (enum config_event_t type , size_t begin , size_t end ,
3011
+ struct config_source * cs , void * data )
3060
3012
{
3061
3013
struct config_store_data * store = data ;
3062
- struct config_source * cs = store -> config_reader -> source ;
3063
3014
3064
3015
ALLOC_GROW (store -> parsed , store -> parsed_nr + 1 , store -> parsed_alloc );
3065
3016
store -> parsed [store -> parsed_nr ].begin = begin ;
@@ -3380,8 +3331,6 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
3380
3331
size_t contents_sz ;
3381
3332
struct config_store_data store = CONFIG_STORE_INIT ;
3382
3333
3383
- store .config_reader = & the_reader ;
3384
-
3385
3334
/* parse-key returns negative; flip the sign to feed exit(3) */
3386
3335
ret = 0 - git_config_parse_key (key , & store .key , & store .baselen );
3387
3336
if (ret )
0 commit comments