@@ -66,40 +66,6 @@ struct config_source {
6666};
6767#define CONFIG_SOURCE_INIT { 0 }
6868
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-
10369static int pack_compression_seen ;
10470static int zlib_compression_seen ;
10571
@@ -752,14 +718,9 @@ int git_config_from_parameters(config_fn_t fn, void *data)
752718 struct strvec to_free = STRVEC_INIT ;
753719 int ret = 0 ;
754720 char * envw = NULL ;
755- struct config_source source = CONFIG_SOURCE_INIT ;
756721 struct key_value_info kvi = KVI_INIT ;
757722
758- source .origin_type = CONFIG_ORIGIN_CMDLINE ;
759- config_reader_push_source (& the_reader , & source );
760-
761723 kvi_from_param (& kvi );
762-
763724 env = getenv (CONFIG_COUNT_ENVIRONMENT );
764725 if (env ) {
765726 unsigned long count ;
@@ -816,7 +777,6 @@ int git_config_from_parameters(config_fn_t fn, void *data)
816777 strbuf_release (& envvar );
817778 strvec_clear (& to_free );
818779 free (envw );
819- config_reader_pop_source (& the_reader );
820780 return ret ;
821781}
822782
@@ -1045,7 +1005,7 @@ static int do_event(struct config_source *cs, enum config_event_t type,
10451005
10461006 if (data -> previous_type != CONFIG_EVENT_EOF &&
10471007 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 )
10491009 return -1 ;
10501010
10511011 data -> previous_type = type ;
@@ -2002,8 +1962,7 @@ int git_default_config(const char *var, const char *value,
20021962 * fgetc, ungetc, ftell of top need to be initialized before calling
20031963 * this function.
20041964 */
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 ,
20071966 void * data , enum config_scope scope ,
20081967 const struct config_options * opts )
20091968{
@@ -2016,21 +1975,17 @@ static int do_config_from(struct config_reader *reader,
20161975 top -> total_len = 0 ;
20171976 strbuf_init (& top -> value , 1024 );
20181977 strbuf_init (& top -> var , 1024 );
2019- config_reader_push_source (reader , top );
20201978 kvi_from_source (top , scope , & kvi );
20211979
20221980 ret = git_parse_source (top , fn , & kvi , data , opts );
20231981
2024- /* pop config-file parsing state stack */
20251982 strbuf_release (& top -> value );
20261983 strbuf_release (& top -> var );
2027- config_reader_pop_source (reader );
20281984
20291985 return ret ;
20301986}
20311987
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 ,
20341989 const enum config_origin_type origin_type ,
20351990 const char * name , const char * path , FILE * f ,
20361991 void * data , enum config_scope scope ,
@@ -2049,16 +2004,16 @@ static int do_config_from_file(struct config_reader *reader,
20492004 top .do_ftell = config_file_ftell ;
20502005
20512006 flockfile (f );
2052- ret = do_config_from (reader , & top , fn , data , scope , opts );
2007+ ret = do_config_from (& top , fn , data , scope , opts );
20532008 funlockfile (f );
20542009 return ret ;
20552010}
20562011
20572012static int git_config_from_stdin (config_fn_t fn , void * data ,
20582013 enum config_scope scope )
20592014{
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 );
20622017}
20632018
20642019int 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,
20722027 BUG ("filename cannot be NULL" );
20732028 f = fopen_or_warn (filename , "r" );
20742029 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 );
20782032 fclose (f );
20792033 }
20802034 return ret ;
@@ -2105,7 +2059,7 @@ int git_config_from_mem(config_fn_t fn,
21052059 top .do_ungetc = config_buf_ungetc ;
21062060 top .do_ftell = config_buf_ftell ;
21072061
2108- return do_config_from (& the_reader , & top , fn , data , scope , opts );
2062+ return do_config_from (& top , fn , data , scope , opts );
21092063}
21102064
21112065int git_config_from_blob_oid (config_fn_t fn ,
@@ -2198,8 +2152,7 @@ int git_config_system(void)
21982152 return !git_env_bool ("GIT_CONFIG_NOSYSTEM" , 0 );
21992153}
22002154
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 ,
22032156 const struct repository * repo ,
22042157 config_fn_t fn , void * data )
22052158{
@@ -2299,7 +2252,7 @@ int config_with_options(config_fn_t fn, void *data,
22992252 ret = git_config_from_blob_ref (fn , repo , config_source -> blob ,
23002253 data , config_source -> scope );
23012254 } else {
2302- ret = do_git_config_sequence (& the_reader , opts , repo , fn , data );
2255+ ret = do_git_config_sequence (opts , repo , fn , data );
23032256 }
23042257
23052258 if (inc .remote_urls ) {
@@ -3009,7 +2962,6 @@ void git_die_config(const char *key, const char *err, ...)
30092962 */
30102963
30112964struct config_store_data {
3012- struct config_reader * config_reader ;
30132965 size_t baselen ;
30142966 char * key ;
30152967 int do_not_match ;
@@ -3055,11 +3007,10 @@ static int matches(const char *key, const char *value,
30553007 (value && !regexec (store -> value_pattern , value , 0 , NULL , 0 ));
30563008}
30573009
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 )
30603012{
30613013 struct config_store_data * store = data ;
3062- struct config_source * cs = store -> config_reader -> source ;
30633014
30643015 ALLOC_GROW (store -> parsed , store -> parsed_nr + 1 , store -> parsed_alloc );
30653016 store -> parsed [store -> parsed_nr ].begin = begin ;
@@ -3380,8 +3331,6 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
33803331 size_t contents_sz ;
33813332 struct config_store_data store = CONFIG_STORE_INIT ;
33823333
3383- store .config_reader = & the_reader ;
3384-
33853334 /* parse-key returns negative; flip the sign to feed exit(3) */
33863335 ret = 0 - git_config_parse_key (key , & store .key , & store .baselen );
33873336 if (ret )
0 commit comments