@@ -1182,34 +1182,36 @@ int git_config_system(void)
1182
1182
return !git_env_bool ("GIT_CONFIG_NOSYSTEM" , 0 );
1183
1183
}
1184
1184
1185
+ static inline int config_early_helper (config_fn_t fn , const char * filename ,
1186
+ void * data , unsigned access_flags , int count ) {
1187
+ if (!filename || access_or_die (filename , R_OK , access_flags ))
1188
+ /* no file: return unchanged */
1189
+ return count ;
1190
+
1191
+ if (git_config_from_file (fn , filename , data ))
1192
+ /* error: decrement or start counting errors at -1 */
1193
+ return count < 0 ? count - 1 : -1 ;
1194
+ else
1195
+ /* ok: increment unless we had errors before */
1196
+ return count < 0 ? count : count + 1 ;
1197
+ }
1198
+
1185
1199
int git_config_early (config_fn_t fn , void * data , const char * repo_config )
1186
1200
{
1187
- int ret = 0 , found = 0 ;
1201
+ /* count loaded files (> 0) or errors (< 0) */
1202
+ int cnt = 0 ;
1188
1203
char * xdg_config = NULL ;
1189
1204
char * user_config = NULL ;
1190
1205
1191
1206
home_config_paths (& user_config , & xdg_config , "config" );
1192
1207
1193
- if (git_config_system () && !access_or_die (git_etc_gitconfig (), R_OK , 0 )) {
1194
- ret += git_config_from_file (fn , git_etc_gitconfig (),
1195
- data );
1196
- found += 1 ;
1197
- }
1198
-
1199
- if (xdg_config && !access_or_die (xdg_config , R_OK , ACCESS_EACCES_OK )) {
1200
- ret += git_config_from_file (fn , xdg_config , data );
1201
- found += 1 ;
1202
- }
1208
+ if (git_config_system ())
1209
+ cnt = config_early_helper (fn , git_etc_gitconfig (), data , 0 , cnt );
1203
1210
1204
- if (user_config && !access_or_die (user_config , R_OK , ACCESS_EACCES_OK )) {
1205
- ret += git_config_from_file (fn , user_config , data );
1206
- found += 1 ;
1207
- }
1211
+ cnt = config_early_helper (fn , xdg_config , data , ACCESS_EACCES_OK , cnt );
1212
+ cnt = config_early_helper (fn , user_config , data , ACCESS_EACCES_OK , cnt );
1208
1213
1209
- if (repo_config && !access_or_die (repo_config , R_OK , 0 )) {
1210
- ret += git_config_from_file (fn , repo_config , data );
1211
- found += 1 ;
1212
- }
1214
+ cnt = config_early_helper (fn , repo_config , data , 0 , cnt );
1213
1215
1214
1216
switch (git_config_from_parameters (fn , data )) {
1215
1217
case -1 : /* error */
@@ -1218,13 +1220,14 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
1218
1220
case 0 : /* found nothing */
1219
1221
break ;
1220
1222
default : /* found at least one item */
1221
- found ++ ;
1223
+ if (cnt >= 0 )
1224
+ cnt ++ ;
1222
1225
break ;
1223
1226
}
1224
1227
1225
1228
free (xdg_config );
1226
1229
free (user_config );
1227
- return ret == 0 ? found : ret ;
1230
+ return cnt ;
1228
1231
}
1229
1232
1230
1233
int git_config_with_options (config_fn_t fn , void * data ,
0 commit comments