@@ -20,14 +20,6 @@ static int zlib_compression_seen;
2020
2121const char * config_exclusive_filename = NULL ;
2222
23- struct config_item {
24- struct config_item * next ;
25- char * name ;
26- char * value ;
27- };
28- static struct config_item * config_parameters ;
29- static struct config_item * * config_parameters_tail = & config_parameters ;
30-
3123static void lowercase (char * p )
3224{
3325 for (; * p ; p ++ )
@@ -47,9 +39,9 @@ void git_config_push_parameter(const char *text)
4739 strbuf_release (& env );
4840}
4941
50- int git_config_parse_parameter (const char * text )
42+ static int git_config_parse_parameter (const char * text ,
43+ config_fn_t fn , void * data )
5144{
52- struct config_item * ct ;
5345 struct strbuf tmp = STRBUF_INIT ;
5446 struct strbuf * * pair ;
5547 strbuf_addstr (& tmp , text );
@@ -59,22 +51,19 @@ int git_config_parse_parameter(const char *text)
5951 strbuf_trim (pair [0 ]);
6052 if (!pair [0 ]-> len ) {
6153 strbuf_list_free (pair );
62- return -1 ;
54+ return error ( "bogus config parameter: %s" , text ) ;
6355 }
64- ct = xcalloc (1 , sizeof (struct config_item ));
65- ct -> name = strbuf_detach (pair [0 ], NULL );
66- if (pair [1 ]) {
67- strbuf_trim (pair [1 ]);
68- ct -> value = strbuf_detach (pair [1 ], NULL );
56+ lowercase (pair [0 ]-> buf );
57+ if (fn (pair [0 ]-> buf , pair [1 ] ? pair [1 ]-> buf : NULL , data ) < 0 ) {
58+ strbuf_list_free (pair );
59+ return -1 ;
6960 }
7061 strbuf_list_free (pair );
71- lowercase (ct -> name );
72- * config_parameters_tail = ct ;
73- config_parameters_tail = & ct -> next ;
7462 return 0 ;
7563}
7664
77- int git_config_parse_environment (void ) {
65+ int git_config_from_parameters (config_fn_t fn , void * data )
66+ {
7867 const char * env = getenv (CONFIG_DATA_ENVIRONMENT );
7968 char * envw ;
8069 const char * * argv = NULL ;
@@ -92,8 +81,7 @@ int git_config_parse_environment(void) {
9281 }
9382
9483 for (i = 0 ; i < nr ; i ++ ) {
95- if (git_config_parse_parameter (argv [i ]) < 0 ) {
96- error ("bogus config parameter: %s" , argv [i ]);
84+ if (git_config_parse_parameter (argv [i ], fn , data ) < 0 ) {
9785 free (argv );
9886 free (envw );
9987 return -1 ;
@@ -102,7 +90,7 @@ int git_config_parse_environment(void) {
10290
10391 free (argv );
10492 free (envw );
105- return 0 ;
93+ return nr > 0 ;
10694}
10795
10896static int get_next_char (void )
@@ -839,22 +827,6 @@ int git_config_system(void)
839827 return !git_env_bool ("GIT_CONFIG_NOSYSTEM" , 0 );
840828}
841829
842- int git_config_from_parameters (config_fn_t fn , void * data )
843- {
844- static int loaded_environment ;
845- const struct config_item * ct ;
846-
847- if (!loaded_environment ) {
848- if (git_config_parse_environment () < 0 )
849- return -1 ;
850- loaded_environment = 1 ;
851- }
852- for (ct = config_parameters ; ct ; ct = ct -> next )
853- if (fn (ct -> name , ct -> value , data ) < 0 )
854- return -1 ;
855- return 0 ;
856- }
857-
858830int git_config_early (config_fn_t fn , void * data , const char * repo_config )
859831{
860832 int ret = 0 , found = 0 ;
@@ -884,9 +856,16 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
884856 found += 1 ;
885857 }
886858
887- ret += git_config_from_parameters (fn , data );
888- if (config_parameters )
889- found += 1 ;
859+ switch (git_config_from_parameters (fn , data )) {
860+ case -1 : /* error */
861+ ret -- ;
862+ break ;
863+ case 0 : /* found nothing */
864+ break ;
865+ default : /* found at least one item */
866+ found ++ ;
867+ break ;
868+ }
890869
891870 return ret == 0 ? found : ret ;
892871}
0 commit comments