change `git_config()` return value to void

Currently `git_config()` returns an integer signifying an error code. During rewrites of the function most of the code was shifted to `git_config_with_options()`. `git_config_with_options()` normally returns positive values if its `config_source` parameter is set as NULL, as most errors are fatal, and non-fatal potential errors are guarded by "if" statements that are entered only when no error is possible. Still a negative value can be returned in case of race condition between `access_or_die()` & `git_config_from_file()`. Also, all callers of `git_config()` ignore the return value except for one case in branch.c. Change `git_config()` return value to void and make it die if it receives a negative value from `git_config_with_options()`. Original-patch-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Tanay Abhra <tanayabh@gmail.com> Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tanay Abhra committed Aug 7, 2014 at 04:59 UTC aace4385027b0366f43961a94c8ed95ac9b3bd53
3 files changed +16 -7
branch.c
+1 -4
@@ -161,10 +161,7 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)
161 strbuf_addf(&name, "branch.%s.description", branch_name);
162 cb.config_name = name.buf;
163 cb.value = NULL;
164 - if (git_config(read_branch_desc_cb, &cb) < 0) {
165 - strbuf_release(&name);
166 - return -1;
167 - }
164 + git_config(read_branch_desc_cb, &cb);
165 if (cb.value)
166 strbuf_addstr(buf, cb.value);
167 strbuf_release(&name);
cache.h
+1 -1
@@ -1294,7 +1294,7 @@ extern int git_config_from_buf(config_fn_t fn, const char *name,
1294 const char *buf, size_t len, void *data);
1295 extern void git_config_push_parameter(const char *text);
1296 extern int git_config_from_parameters(config_fn_t fn, void *data);
1297 -extern int git_config(config_fn_t fn, void *);
1297 +extern void git_config(config_fn_t fn, void *);
1298 extern int git_config_with_options(config_fn_t fn, void *,
1299 struct git_config_source *config_source,
1300 int respect_includes);
config.c
+14 -2
@@ -1232,9 +1232,21 @@ int git_config_with_options(config_fn_t fn, void *data,
1232 return ret;
1233 }
1234
1235 -int git_config(config_fn_t fn, void *data)
1235 +void git_config(config_fn_t fn, void *data)
1236 {
1237 - return git_config_with_options(fn, data, NULL, 1);
1237 + if (git_config_with_options(fn, data, NULL, 1) < 0)
1238 + /*
1239 + * git_config_with_options() normally returns only
1240 + * positive values, as most errors are fatal, and
1241 + * non-fatal potential errors are guarded by "if"
1242 + * statements that are entered only when no error is
1243 + * possible.
1244 + *
1245 + * If we ever encounter a non-fatal error, it means
1246 + * something went really wrong and we should stop
1247 + * immediately.
1248 + */
1249 + die(_("unknown error occured while reading the configuration files"));
1250 }
1251
1252 static struct config_set_element *configset_find_element(struct config_set *cs, const char *key)