Skip to content

Commit 8868b1e

Browse files
chooglengitster
authored andcommitted
config: pass kvi to die_bad_number()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dc90208 commit 8868b1e

27 files changed

+190
-182
lines changed

archive-tar.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,14 @@ static int tar_filter_config(const char *var, const char *value,
412412
}
413413

414414
static int git_tar_config(const char *var, const char *value,
415-
const struct config_context *ctx UNUSED, void *cb)
415+
const struct config_context *ctx, void *cb)
416416
{
417417
if (!strcmp(var, "tar.umask")) {
418418
if (value && !strcmp(value, "user")) {
419419
tar_umask = umask(0);
420420
umask(tar_umask);
421421
} else {
422-
tar_umask = git_config_int(var, value);
422+
tar_umask = git_config_int(var, value, ctx->kvi);
423423
}
424424
return 0;
425425
}

builtin/commit-graph.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ static int write_option_max_new_filters(const struct option *opt,
186186
}
187187

188188
static int git_commit_graph_write_config(const char *var, const char *value,
189-
const struct config_context *ctx UNUSED,
189+
const struct config_context *ctx,
190190
void *cb UNUSED)
191191
{
192192
if (!strcmp(var, "commitgraph.maxnewfilters"))
193-
write_opts.max_new_filters = git_config_int(var, value);
193+
write_opts.max_new_filters = git_config_int(var, value, ctx->kvi);
194194
/*
195195
* No need to fall-back to 'git_default_config', since this was already
196196
* called in 'cmd_commit_graph()'.

builtin/commit.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,8 @@ static int git_status_config(const char *k, const char *v,
14151415
return git_column_config(k, v, "status", &s->colopts);
14161416
if (!strcmp(k, "status.submodulesummary")) {
14171417
int is_bool;
1418-
s->submodule_summary = git_config_bool_or_int(k, v, &is_bool);
1418+
s->submodule_summary = git_config_bool_or_int(k, v, ctx->kvi,
1419+
&is_bool);
14191420
if (is_bool && s->submodule_summary)
14201421
s->submodule_summary = -1;
14211422
return 0;
@@ -1475,11 +1476,11 @@ static int git_status_config(const char *k, const char *v,
14751476
}
14761477
if (!strcmp(k, "diff.renamelimit")) {
14771478
if (s->rename_limit == -1)
1478-
s->rename_limit = git_config_int(k, v);
1479+
s->rename_limit = git_config_int(k, v, ctx->kvi);
14791480
return 0;
14801481
}
14811482
if (!strcmp(k, "status.renamelimit")) {
1482-
s->rename_limit = git_config_int(k, v);
1483+
s->rename_limit = git_config_int(k, v, ctx->kvi);
14831484
return 0;
14841485
}
14851486
if (!strcmp(k, "diff.renames")) {
@@ -1625,7 +1626,8 @@ static int git_commit_config(const char *k, const char *v,
16251626
}
16261627
if (!strcmp(k, "commit.verbose")) {
16271628
int is_bool;
1628-
config_commit_verbose = git_config_bool_or_int(k, v, &is_bool);
1629+
config_commit_verbose = git_config_bool_or_int(k, v, ctx->kvi,
1630+
&is_bool);
16291631
return 0;
16301632
}
16311633

builtin/config.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,14 @@ static int format_config(struct strbuf *buf, const char *key_,
262262

263263
if (type == TYPE_INT)
264264
strbuf_addf(buf, "%"PRId64,
265-
git_config_int64(key_, value_ ? value_ : ""));
265+
git_config_int64(key_, value_ ? value_ : "", kvi));
266266
else if (type == TYPE_BOOL)
267267
strbuf_addstr(buf, git_config_bool(key_, value_) ?
268268
"true" : "false");
269269
else if (type == TYPE_BOOL_OR_INT) {
270270
int is_bool, v;
271-
v = git_config_bool_or_int(key_, value_, &is_bool);
271+
v = git_config_bool_or_int(key_, value_, kvi,
272+
&is_bool);
272273
if (is_bool)
273274
strbuf_addstr(buf, v ? "true" : "false");
274275
else
@@ -424,7 +425,8 @@ static int get_value(const char *key_, const char *regex_, unsigned flags)
424425
return ret;
425426
}
426427

427-
static char *normalize_value(const char *key, const char *value)
428+
static char *normalize_value(const char *key, const char *value,
429+
struct key_value_info *kvi)
428430
{
429431
if (!value)
430432
return NULL;
@@ -439,12 +441,12 @@ static char *normalize_value(const char *key, const char *value)
439441
*/
440442
return xstrdup(value);
441443
if (type == TYPE_INT)
442-
return xstrfmt("%"PRId64, git_config_int64(key, value));
444+
return xstrfmt("%"PRId64, git_config_int64(key, value, kvi));
443445
if (type == TYPE_BOOL)
444446
return xstrdup(git_config_bool(key, value) ? "true" : "false");
445447
if (type == TYPE_BOOL_OR_INT) {
446448
int is_bool, v;
447-
v = git_config_bool_or_int(key, value, &is_bool);
449+
v = git_config_bool_or_int(key, value, kvi, &is_bool);
448450
if (!is_bool)
449451
return xstrfmt("%d", v);
450452
else
@@ -674,6 +676,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
674676
char *value = NULL;
675677
int flags = 0;
676678
int ret = 0;
679+
struct key_value_info default_kvi = KVI_INIT;
677680

678681
given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT));
679682

@@ -891,7 +894,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
891894
else if (actions == ACTION_SET) {
892895
check_write();
893896
check_argc(argc, 2, 2);
894-
value = normalize_value(argv[0], argv[1]);
897+
value = normalize_value(argv[0], argv[1], &default_kvi);
895898
ret = git_config_set_in_file_gently(given_config_source.file, argv[0], value);
896899
if (ret == CONFIG_NOTHING_SET)
897900
error(_("cannot overwrite multiple values with a single value\n"
@@ -900,15 +903,15 @@ int cmd_config(int argc, const char **argv, const char *prefix)
900903
else if (actions == ACTION_SET_ALL) {
901904
check_write();
902905
check_argc(argc, 2, 3);
903-
value = normalize_value(argv[0], argv[1]);
906+
value = normalize_value(argv[0], argv[1], &default_kvi);
904907
ret = git_config_set_multivar_in_file_gently(given_config_source.file,
905908
argv[0], value, argv[2],
906909
flags);
907910
}
908911
else if (actions == ACTION_ADD) {
909912
check_write();
910913
check_argc(argc, 2, 2);
911-
value = normalize_value(argv[0], argv[1]);
914+
value = normalize_value(argv[0], argv[1], &default_kvi);
912915
ret = git_config_set_multivar_in_file_gently(given_config_source.file,
913916
argv[0], value,
914917
CONFIG_REGEX_NONE,
@@ -917,7 +920,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
917920
else if (actions == ACTION_REPLACE_ALL) {
918921
check_write();
919922
check_argc(argc, 2, 3);
920-
value = normalize_value(argv[0], argv[1]);
923+
value = normalize_value(argv[0], argv[1], &default_kvi);
921924
ret = git_config_set_multivar_in_file_gently(given_config_source.file,
922925
argv[0], value, argv[2],
923926
flags | CONFIG_FLAGS_MULTI_REPLACE);

builtin/fetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ static int git_fetch_config(const char *k, const char *v,
137137
}
138138

139139
if (!strcmp(k, "submodule.fetchjobs")) {
140-
fetch_config->submodule_fetch_jobs = parse_submodule_fetchjobs(k, v);
140+
fetch_config->submodule_fetch_jobs = parse_submodule_fetchjobs(k, v, ctx->kvi);
141141
return 0;
142142
} else if (!strcmp(k, "fetch.recursesubmodules")) {
143143
fetch_config->recurse_submodules = parse_fetch_recurse_submodules_arg(k, v);
144144
return 0;
145145
}
146146

147147
if (!strcmp(k, "fetch.parallel")) {
148-
fetch_config->parallel = git_config_int(k, v);
148+
fetch_config->parallel = git_config_int(k, v, ctx->kvi);
149149
if (fetch_config->parallel < 0)
150150
die(_("fetch.parallel cannot be negative"));
151151
if (!fetch_config->parallel)

builtin/fsmonitor--daemon.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static int fsmonitor_config(const char *var, const char *value,
4141
const struct config_context *ctx, void *cb)
4242
{
4343
if (!strcmp(var, FSMONITOR__IPC_THREADS)) {
44-
int i = git_config_int(var, value);
44+
int i = git_config_int(var, value, ctx->kvi);
4545
if (i < 1)
4646
return error(_("value of '%s' out of range: %d"),
4747
FSMONITOR__IPC_THREADS, i);
@@ -50,7 +50,7 @@ static int fsmonitor_config(const char *var, const char *value,
5050
}
5151

5252
if (!strcmp(var, FSMONITOR__START_TIMEOUT)) {
53-
int i = git_config_int(var, value);
53+
int i = git_config_int(var, value, ctx->kvi);
5454
if (i < 0)
5555
return error(_("value of '%s' out of range: %d"),
5656
FSMONITOR__START_TIMEOUT, i);
@@ -60,7 +60,7 @@ static int fsmonitor_config(const char *var, const char *value,
6060

6161
if (!strcmp(var, FSMONITOR__ANNOUNCE_STARTUP)) {
6262
int is_bool;
63-
int i = git_config_bool_or_int(var, value, &is_bool);
63+
int i = git_config_bool_or_int(var, value, ctx->kvi, &is_bool);
6464
if (i < 0)
6565
return error(_("value of '%s' not bool or int: %d"),
6666
var, i);

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static int grep_cmd_config(const char *var, const char *value,
301301
st = -1;
302302

303303
if (!strcmp(var, "grep.threads")) {
304-
num_threads = git_config_int(var, value);
304+
num_threads = git_config_int(var, value, ctx->kvi);
305305
if (num_threads < 0)
306306
die(_("invalid number of threads specified (%d) for %s"),
307307
num_threads, var);

builtin/index-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,13 +1587,13 @@ static int git_index_pack_config(const char *k, const char *v,
15871587
struct pack_idx_option *opts = cb;
15881588

15891589
if (!strcmp(k, "pack.indexversion")) {
1590-
opts->version = git_config_int(k, v);
1590+
opts->version = git_config_int(k, v, ctx->kvi);
15911591
if (opts->version > 2)
15921592
die(_("bad pack.indexVersion=%"PRIu32), opts->version);
15931593
return 0;
15941594
}
15951595
if (!strcmp(k, "pack.threads")) {
1596-
nr_threads = git_config_int(k, v);
1596+
nr_threads = git_config_int(k, v, ctx->kvi);
15971597
if (nr_threads < 0)
15981598
die(_("invalid number of threads specified (%d)"),
15991599
nr_threads);

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ static int git_log_config(const char *var, const char *value,
574574
if (!strcmp(var, "format.subjectprefix"))
575575
return git_config_string(&fmt_patch_subject_prefix, var, value);
576576
if (!strcmp(var, "format.filenamemaxlength")) {
577-
fmt_patch_name_max = git_config_int(var, value);
577+
fmt_patch_name_max = git_config_int(var, value, ctx->kvi);
578578
return 0;
579579
}
580580
if (!strcmp(var, "format.encodeemailheaders")) {

builtin/pack-objects.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,23 +3139,23 @@ static int git_pack_config(const char *k, const char *v,
31393139
const struct config_context *ctx, void *cb)
31403140
{
31413141
if (!strcmp(k, "pack.window")) {
3142-
window = git_config_int(k, v);
3142+
window = git_config_int(k, v, ctx->kvi);
31433143
return 0;
31443144
}
31453145
if (!strcmp(k, "pack.windowmemory")) {
3146-
window_memory_limit = git_config_ulong(k, v);
3146+
window_memory_limit = git_config_ulong(k, v, ctx->kvi);
31473147
return 0;
31483148
}
31493149
if (!strcmp(k, "pack.depth")) {
3150-
depth = git_config_int(k, v);
3150+
depth = git_config_int(k, v, ctx->kvi);
31513151
return 0;
31523152
}
31533153
if (!strcmp(k, "pack.deltacachesize")) {
3154-
max_delta_cache_size = git_config_int(k, v);
3154+
max_delta_cache_size = git_config_int(k, v, ctx->kvi);
31553155
return 0;
31563156
}
31573157
if (!strcmp(k, "pack.deltacachelimit")) {
3158-
cache_max_small_delta_size = git_config_int(k, v);
3158+
cache_max_small_delta_size = git_config_int(k, v, ctx->kvi);
31593159
return 0;
31603160
}
31613161
if (!strcmp(k, "pack.writebitmaphashcache")) {
@@ -3181,7 +3181,7 @@ static int git_pack_config(const char *k, const char *v,
31813181
return 0;
31823182
}
31833183
if (!strcmp(k, "pack.threads")) {
3184-
delta_search_threads = git_config_int(k, v);
3184+
delta_search_threads = git_config_int(k, v, ctx->kvi);
31853185
if (delta_search_threads < 0)
31863186
die(_("invalid number of threads specified (%d)"),
31873187
delta_search_threads);
@@ -3192,7 +3192,7 @@ static int git_pack_config(const char *k, const char *v,
31923192
return 0;
31933193
}
31943194
if (!strcmp(k, "pack.indexversion")) {
3195-
pack_idx_opts.version = git_config_int(k, v);
3195+
pack_idx_opts.version = git_config_int(k, v, ctx->kvi);
31963196
if (pack_idx_opts.version > 2)
31973197
die(_("bad pack.indexVersion=%"PRIu32),
31983198
pack_idx_opts.version);

0 commit comments

Comments
 (0)