Plumb "struct key_value_info" through all code paths that end in
die_bad_number(), which lets us remove the helper functions that read
analogous values from "struct config_reader". As a result, nothing reads
config_reader.config_kvi any more, so remove that too.
In config.c, this requires changing the signature of
git_configset_get_value() to 'return' "kvi" in an out parameter so that
git_configset_get_<type>() can pass it to git_config_<type>(). Only
numeric types will use "kvi", so for non-numeric types (e.g.
git_configset_get_string()), pass NULL to indicate that the out
parameter isn't needed.
Outside of config.c, config callbacks now need to pass "ctx->kvi" to any
of the git_config_<type>() functions that parse a config string into a
number type. Included is a .cocci patch to make that refactor.
The only exceptional case is builtin/config.c, where git_config_<type>()
is called outside of a config callback (namely, on user-provided input),
so config source information has never been available. In this case,
die_bad_number() defaults to a generic, but perfectly descriptive
message. Let's provide a safe, non-NULL for "kvi" anyway, but make sure
not to change the message.
Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Glen Choo committedJun 28, 2023 at 19:26 UTC8868b1ebfb8274a3ef90e1ba69ed45be94f6c3fb
index 1185c49239..b071c5ab64 100644--- a/builtin/commit-graph.c+++ b/builtin/commit-graph.c@@ -186,11 +186,11 @@ static int write_option_max_new_filters(const struct option *opt, } static int git_commit_graph_write_config(const char *var, const char *value,- const struct config_context *ctx UNUSED,+ const struct config_context *ctx, void *cb UNUSED) { if (!strcmp(var, "commitgraph.maxnewfilters"))- write_opts.max_new_filters = git_config_int(var, value);+ write_opts.max_new_filters = git_config_int(var, value, ctx->kvi); /* * No need to fall-back to 'git_default_config', since this was already * called in 'cmd_commit_graph()'.
index 9b9f552731..680269d263 100644--- a/builtin/config.c+++ b/builtin/config.c@@ -262,13 +262,14 @@ static int format_config(struct strbuf *buf, const char *key_, if (type == TYPE_INT) strbuf_addf(buf, "%"PRId64,- git_config_int64(key_, value_ ? value_ : ""));+ git_config_int64(key_, value_ ? value_ : "", kvi)); else if (type == TYPE_BOOL) strbuf_addstr(buf, git_config_bool(key_, value_) ? "true" : "false"); else if (type == TYPE_BOOL_OR_INT) { int is_bool, v;- v = git_config_bool_or_int(key_, value_, &is_bool);+ v = git_config_bool_or_int(key_, value_, kvi,+ &is_bool); if (is_bool) strbuf_addstr(buf, v ? "true" : "false"); else@@ -424,7 +425,8 @@ free_strings: return ret; }-static char *normalize_value(const char *key, const char *value)+static char *normalize_value(const char *key, const char *value,+ struct key_value_info *kvi) { if (!value) return NULL;@@ -439,12 +441,12 @@ static char *normalize_value(const char *key, const char *value) */ return xstrdup(value); if (type == TYPE_INT)- return xstrfmt("%"PRId64, git_config_int64(key, value));+ return xstrfmt("%"PRId64, git_config_int64(key, value, kvi)); if (type == TYPE_BOOL) return xstrdup(git_config_bool(key, value) ? "true" : "false"); if (type == TYPE_BOOL_OR_INT) { int is_bool, v;- v = git_config_bool_or_int(key, value, &is_bool);+ v = git_config_bool_or_int(key, value, kvi, &is_bool); if (!is_bool) return xstrfmt("%d", v); else@@ -674,6 +676,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) char *value = NULL; int flags = 0; int ret = 0;+ struct key_value_info default_kvi = KVI_INIT; given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT));@@ -891,7 +894,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) else if (actions == ACTION_SET) { check_write(); check_argc(argc, 2, 2);- value = normalize_value(argv[0], argv[1]);+ value = normalize_value(argv[0], argv[1], &default_kvi); ret = git_config_set_in_file_gently(given_config_source.file, argv[0], value); if (ret == CONFIG_NOTHING_SET) error(_("cannot overwrite multiple values with a single value\n"@@ -900,7 +903,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) else if (actions == ACTION_SET_ALL) { check_write(); check_argc(argc, 2, 3);- value = normalize_value(argv[0], argv[1]);+ value = normalize_value(argv[0], argv[1], &default_kvi); ret = git_config_set_multivar_in_file_gently(given_config_source.file, argv[0], value, argv[2], flags);@@ -908,7 +911,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) else if (actions == ACTION_ADD) { check_write(); check_argc(argc, 2, 2);- value = normalize_value(argv[0], argv[1]);+ value = normalize_value(argv[0], argv[1], &default_kvi); ret = git_config_set_multivar_in_file_gently(given_config_source.file, argv[0], value, CONFIG_REGEX_NONE,@@ -917,7 +920,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) else if (actions == ACTION_REPLACE_ALL) { check_write(); check_argc(argc, 2, 3);- value = normalize_value(argv[0], argv[1]);+ value = normalize_value(argv[0], argv[1], &default_kvi); ret = git_config_set_multivar_in_file_gently(given_config_source.file, argv[0], value, argv[2], flags | CONFIG_FLAGS_MULTI_REPLACE);
builtin/fetch.c
+2-2
index a4aa0fbb8f..fe86dfeb62 100644--- a/builtin/fetch.c+++ b/builtin/fetch.c@@ -137,7 +137,7 @@ static int git_fetch_config(const char *k, const char *v, } if (!strcmp(k, "submodule.fetchjobs")) {- fetch_config->submodule_fetch_jobs = parse_submodule_fetchjobs(k, v);+ fetch_config->submodule_fetch_jobs = parse_submodule_fetchjobs(k, v, ctx->kvi); return 0; } else if (!strcmp(k, "fetch.recursesubmodules")) { fetch_config->recurse_submodules = parse_fetch_recurse_submodules_arg(k, v);@@ -145,7 +145,7 @@ static int git_fetch_config(const char *k, const char *v, } if (!strcmp(k, "fetch.parallel")) {- fetch_config->parallel = git_config_int(k, v);+ fetch_config->parallel = git_config_int(k, v, ctx->kvi); if (fetch_config->parallel < 0) die(_("fetch.parallel cannot be negative")); if (!fetch_config->parallel)
builtin/fsmonitor--daemon.c
+3-3
index 91a776e2f1..6d2826b07d 100644--- a/builtin/fsmonitor--daemon.c+++ b/builtin/fsmonitor--daemon.c@@ -41,7 +41,7 @@ static int fsmonitor_config(const char *var, const char *value, const struct config_context *ctx, void *cb) { if (!strcmp(var, FSMONITOR__IPC_THREADS)) {- int i = git_config_int(var, value);+ int i = git_config_int(var, value, ctx->kvi); if (i < 1) return error(_("value of '%s' out of range: %d"), FSMONITOR__IPC_THREADS, i);@@ -50,7 +50,7 @@ static int fsmonitor_config(const char *var, const char *value, } if (!strcmp(var, FSMONITOR__START_TIMEOUT)) {- int i = git_config_int(var, value);+ int i = git_config_int(var, value, ctx->kvi); if (i < 0) return error(_("value of '%s' out of range: %d"), FSMONITOR__START_TIMEOUT, i);@@ -60,7 +60,7 @@ static int fsmonitor_config(const char *var, const char *value, if (!strcmp(var, FSMONITOR__ANNOUNCE_STARTUP)) { int is_bool;- int i = git_config_bool_or_int(var, value, &is_bool);+ int i = git_config_bool_or_int(var, value, ctx->kvi, &is_bool); if (i < 0) return error(_("value of '%s' not bool or int: %d"), var, i);
builtin/grep.c
+1-1
index 757d52b94e..3a464e6faa 100644--- a/builtin/grep.c+++ b/builtin/grep.c@@ -301,7 +301,7 @@ static int grep_cmd_config(const char *var, const char *value, st = -1; if (!strcmp(var, "grep.threads")) {- num_threads = git_config_int(var, value);+ num_threads = git_config_int(var, value, ctx->kvi); if (num_threads < 0) die(_("invalid number of threads specified (%d) for %s"), num_threads, var);
builtin/index-pack.c
+2-2
index de8884ea5c..e428f6d9a4 100644--- a/builtin/index-pack.c+++ b/builtin/index-pack.c@@ -1587,13 +1587,13 @@ static int git_index_pack_config(const char *k, const char *v, struct pack_idx_option *opts = cb; if (!strcmp(k, "pack.indexversion")) {- opts->version = git_config_int(k, v);+ opts->version = git_config_int(k, v, ctx->kvi); if (opts->version > 2) die(_("bad pack.indexVersion=%"PRIu32), opts->version); return 0; } if (!strcmp(k, "pack.threads")) {- nr_threads = git_config_int(k, v);+ nr_threads = git_config_int(k, v, ctx->kvi); if (nr_threads < 0) die(_("invalid number of threads specified (%d)"), nr_threads);
builtin/log.c
+1-1
index 09d6a13075..c7337354aa 100644--- a/builtin/log.c+++ b/builtin/log.c@@ -574,7 +574,7 @@ static int git_log_config(const char *var, const char *value, if (!strcmp(var, "format.subjectprefix")) return git_config_string(&fmt_patch_subject_prefix, var, value); if (!strcmp(var, "format.filenamemaxlength")) {- fmt_patch_name_max = git_config_int(var, value);+ fmt_patch_name_max = git_config_int(var, value, ctx->kvi); return 0; } if (!strcmp(var, "format.encodeemailheaders")) {
index c448fecd4b..af277ec901 100644--- a/worktree.c+++ b/worktree.c@@ -835,7 +835,7 @@ int init_worktree_config(struct repository *r) * Relocate that value to avoid breaking all worktrees with this * upgrade to worktree config. */- if (!git_configset_get_value(&cs, "core.worktree", &core_worktree)) {+ if (!git_configset_get_value(&cs, "core.worktree", &core_worktree, NULL)) { if ((res = move_config_setting("core.worktree", core_worktree, common_config_file, main_worktree_file)))