git_config_with_options: drop "found" counting

Prior to 1f2baa7 (config: treat non-existent config files as empty, 2010-10-21), we returned an error if any config files were missing. That commit made this a non-error, but returned the number of sources found, in case any caller wanted to distinguish this case. In the past 5+ years, no caller has; the only two places which bother to check the return value care only about the error case. Let's drop this code, which complicates the function. Similarly, let's drop the "found anything" return from git_config_from_parameters, which was present only to support this (and similarly has never had other callers care for the past 5+ years). Note that we do need to update a comment in one of the callers, even though the code immediately below it doesn't care about this case. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 18, 2016 at 18:39 UTC c72ee44bf4bc7549ee8710037ae8adfae6d8efc2
1 file changed +9 -25
config.c
+9 -25
@@ -230,7 +230,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
230
231 free(argv);
232 free(envw);
233 - return nr > 0;
233 + return 0;
234 }
235
236 static int get_next_char(void)
@@ -1197,47 +1197,31 @@ int git_config_system(void)
1197
1198 static int do_git_config_sequence(config_fn_t fn, void *data)
1199 {
1200 - int ret = 0, found = 0;
1200 + int ret = 0;
1201 char *xdg_config = xdg_config_home("config");
1202 char *user_config = expand_user_path("~/.gitconfig");
1203 char *repo_config = git_pathdup("config");
1204
1205 - if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0)) {
1205 + if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0))
1206 ret += git_config_from_file(fn, git_etc_gitconfig(),
1207 data);
1208 - found += 1;
1209 - }
1208
1211 - if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK)) {
1209 + if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK))
1210 ret += git_config_from_file(fn, xdg_config, data);
1213 - found += 1;
1214 - }
1211
1216 - if (user_config && !access_or_die(user_config, R_OK, ACCESS_EACCES_OK)) {
1212 + if (user_config && !access_or_die(user_config, R_OK, ACCESS_EACCES_OK))
1213 ret += git_config_from_file(fn, user_config, data);
1218 - found += 1;
1219 - }
1214
1221 - if (repo_config && !access_or_die(repo_config, R_OK, 0)) {
1215 + if (repo_config && !access_or_die(repo_config, R_OK, 0))
1216 ret += git_config_from_file(fn, repo_config, data);
1223 - found += 1;
1224 - }
1217
1226 - switch (git_config_from_parameters(fn, data)) {
1227 - case -1: /* error */
1218 + if (git_config_from_parameters(fn, data) < 0)
1219 die(_("unable to parse command-line config"));
1229 - break;
1230 - case 0: /* found nothing */
1231 - break;
1232 - default: /* found at least one item */
1233 - found++;
1234 - break;
1235 - }
1220
1221 free(xdg_config);
1222 free(user_config);
1223 free(repo_config);
1240 - return ret == 0 ? found : ret;
1224 + return ret;
1225 }
1226
1227 int git_config_with_options(config_fn_t fn, void *data,
@@ -1272,7 +1256,7 @@ static void git_config_raw(config_fn_t fn, void *data)
1256 if (git_config_with_options(fn, data, NULL, 1) < 0)
1257 /*
1258 * git_config_with_options() normally returns only
1275 - * positive values, as most errors are fatal, and
1259 + * zero, as most errors are fatal, and
1260 * non-fatal potential errors are guarded by "if"
1261 * statements that are entered only when no error is
1262 * possible.