@@ -20,14 +20,6 @@ static int zlib_compression_seen;
20
20
21
21
const char * config_exclusive_filename = NULL ;
22
22
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
-
31
23
static void lowercase (char * p )
32
24
{
33
25
for (; * p ; p ++ )
@@ -47,9 +39,9 @@ void git_config_push_parameter(const char *text)
47
39
strbuf_release (& env );
48
40
}
49
41
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 )
51
44
{
52
- struct config_item * ct ;
53
45
struct strbuf tmp = STRBUF_INIT ;
54
46
struct strbuf * * pair ;
55
47
strbuf_addstr (& tmp , text );
@@ -59,22 +51,19 @@ int git_config_parse_parameter(const char *text)
59
51
strbuf_trim (pair [0 ]);
60
52
if (!pair [0 ]-> len ) {
61
53
strbuf_list_free (pair );
62
- return -1 ;
54
+ return error ( "bogus config parameter: %s" , text ) ;
63
55
}
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 ;
69
60
}
70
61
strbuf_list_free (pair );
71
- lowercase (ct -> name );
72
- * config_parameters_tail = ct ;
73
- config_parameters_tail = & ct -> next ;
74
62
return 0 ;
75
63
}
76
64
77
- int git_config_parse_environment (void ) {
65
+ int git_config_from_parameters (config_fn_t fn , void * data )
66
+ {
78
67
const char * env = getenv (CONFIG_DATA_ENVIRONMENT );
79
68
char * envw ;
80
69
const char * * argv = NULL ;
@@ -92,8 +81,7 @@ int git_config_parse_environment(void) {
92
81
}
93
82
94
83
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 ) {
97
85
free (argv );
98
86
free (envw );
99
87
return -1 ;
@@ -102,7 +90,7 @@ int git_config_parse_environment(void) {
102
90
103
91
free (argv );
104
92
free (envw );
105
- return 0 ;
93
+ return nr > 0 ;
106
94
}
107
95
108
96
static int get_next_char (void )
@@ -839,22 +827,6 @@ int git_config_system(void)
839
827
return !git_env_bool ("GIT_CONFIG_NOSYSTEM" , 0 );
840
828
}
841
829
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
-
858
830
int git_config_early (config_fn_t fn , void * data , const char * repo_config )
859
831
{
860
832
int ret = 0 , found = 0 ;
@@ -884,9 +856,16 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
884
856
found += 1 ;
885
857
}
886
858
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
+ }
890
869
891
870
return ret == 0 ? found : ret ;
892
871
}
0 commit comments