Skip to content

Commit c72ee44

Browse files
peffgitster
authored andcommitted
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>
1 parent 3a0f269 commit c72ee44

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

config.c

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
230230

231231
free(argv);
232232
free(envw);
233-
return nr > 0;
233+
return 0;
234234
}
235235

236236
static int get_next_char(void)
@@ -1197,47 +1197,31 @@ int git_config_system(void)
11971197

11981198
static int do_git_config_sequence(config_fn_t fn, void *data)
11991199
{
1200-
int ret = 0, found = 0;
1200+
int ret = 0;
12011201
char *xdg_config = xdg_config_home("config");
12021202
char *user_config = expand_user_path("~/.gitconfig");
12031203
char *repo_config = git_pathdup("config");
12041204

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))
12061206
ret += git_config_from_file(fn, git_etc_gitconfig(),
12071207
data);
1208-
found += 1;
1209-
}
12101208

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))
12121210
ret += git_config_from_file(fn, xdg_config, data);
1213-
found += 1;
1214-
}
12151211

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))
12171213
ret += git_config_from_file(fn, user_config, data);
1218-
found += 1;
1219-
}
12201214

1221-
if (repo_config && !access_or_die(repo_config, R_OK, 0)) {
1215+
if (repo_config && !access_or_die(repo_config, R_OK, 0))
12221216
ret += git_config_from_file(fn, repo_config, data);
1223-
found += 1;
1224-
}
12251217

1226-
switch (git_config_from_parameters(fn, data)) {
1227-
case -1: /* error */
1218+
if (git_config_from_parameters(fn, data) < 0)
12281219
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-
}
12361220

12371221
free(xdg_config);
12381222
free(user_config);
12391223
free(repo_config);
1240-
return ret == 0 ? found : ret;
1224+
return ret;
12411225
}
12421226

12431227
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)
12721256
if (git_config_with_options(fn, data, NULL, 1) < 0)
12731257
/*
12741258
* git_config_with_options() normally returns only
1275-
* positive values, as most errors are fatal, and
1259+
* zero, as most errors are fatal, and
12761260
* non-fatal potential errors are guarded by "if"
12771261
* statements that are entered only when no error is
12781262
* possible.

0 commit comments

Comments
 (0)