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 <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Glen Choo
2023-06-28 19:26:27 +00:00
committed by Junio C Hamano
parent dc90208497
commit 8868b1ebfb
27 changed files with 190 additions and 182 deletions

View File

@@ -412,14 +412,14 @@ static int tar_filter_config(const char *var, const char *value,
} }
static int git_tar_config(const char *var, const char *value, static int git_tar_config(const char *var, const char *value,
const struct config_context *ctx UNUSED, void *cb) const struct config_context *ctx, void *cb)
{ {
if (!strcmp(var, "tar.umask")) { if (!strcmp(var, "tar.umask")) {
if (value && !strcmp(value, "user")) { if (value && !strcmp(value, "user")) {
tar_umask = umask(0); tar_umask = umask(0);
umask(tar_umask); umask(tar_umask);
} else { } else {
tar_umask = git_config_int(var, value); tar_umask = git_config_int(var, value, ctx->kvi);
} }
return 0; return 0;
} }

View File

@@ -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, 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) void *cb UNUSED)
{ {
if (!strcmp(var, "commitgraph.maxnewfilters")) 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 * No need to fall-back to 'git_default_config', since this was already
* called in 'cmd_commit_graph()'. * called in 'cmd_commit_graph()'.

View File

@@ -1415,7 +1415,8 @@ static int git_status_config(const char *k, const char *v,
return git_column_config(k, v, "status", &s->colopts); return git_column_config(k, v, "status", &s->colopts);
if (!strcmp(k, "status.submodulesummary")) { if (!strcmp(k, "status.submodulesummary")) {
int is_bool; int is_bool;
s->submodule_summary = git_config_bool_or_int(k, v, &is_bool); s->submodule_summary = git_config_bool_or_int(k, v, ctx->kvi,
&is_bool);
if (is_bool && s->submodule_summary) if (is_bool && s->submodule_summary)
s->submodule_summary = -1; s->submodule_summary = -1;
return 0; return 0;
@@ -1475,11 +1476,11 @@ static int git_status_config(const char *k, const char *v,
} }
if (!strcmp(k, "diff.renamelimit")) { if (!strcmp(k, "diff.renamelimit")) {
if (s->rename_limit == -1) if (s->rename_limit == -1)
s->rename_limit = git_config_int(k, v); s->rename_limit = git_config_int(k, v, ctx->kvi);
return 0; return 0;
} }
if (!strcmp(k, "status.renamelimit")) { if (!strcmp(k, "status.renamelimit")) {
s->rename_limit = git_config_int(k, v); s->rename_limit = git_config_int(k, v, ctx->kvi);
return 0; return 0;
} }
if (!strcmp(k, "diff.renames")) { if (!strcmp(k, "diff.renames")) {
@@ -1625,7 +1626,8 @@ static int git_commit_config(const char *k, const char *v,
} }
if (!strcmp(k, "commit.verbose")) { if (!strcmp(k, "commit.verbose")) {
int is_bool; int is_bool;
config_commit_verbose = git_config_bool_or_int(k, v, &is_bool); config_commit_verbose = git_config_bool_or_int(k, v, ctx->kvi,
&is_bool);
return 0; return 0;
} }

View File

@@ -262,13 +262,14 @@ static int format_config(struct strbuf *buf, const char *key_,
if (type == TYPE_INT) if (type == TYPE_INT)
strbuf_addf(buf, "%"PRId64, strbuf_addf(buf, "%"PRId64,
git_config_int64(key_, value_ ? value_ : "")); git_config_int64(key_, value_ ? value_ : "", kvi));
else if (type == TYPE_BOOL) else if (type == TYPE_BOOL)
strbuf_addstr(buf, git_config_bool(key_, value_) ? strbuf_addstr(buf, git_config_bool(key_, value_) ?
"true" : "false"); "true" : "false");
else if (type == TYPE_BOOL_OR_INT) { else if (type == TYPE_BOOL_OR_INT) {
int is_bool, v; 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) if (is_bool)
strbuf_addstr(buf, v ? "true" : "false"); strbuf_addstr(buf, v ? "true" : "false");
else else
@@ -424,7 +425,8 @@ free_strings:
return ret; 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) if (!value)
return NULL; return NULL;
@@ -439,12 +441,12 @@ static char *normalize_value(const char *key, const char *value)
*/ */
return xstrdup(value); return xstrdup(value);
if (type == TYPE_INT) 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) if (type == TYPE_BOOL)
return xstrdup(git_config_bool(key, value) ? "true" : "false"); return xstrdup(git_config_bool(key, value) ? "true" : "false");
if (type == TYPE_BOOL_OR_INT) { if (type == TYPE_BOOL_OR_INT) {
int is_bool, v; 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) if (!is_bool)
return xstrfmt("%d", v); return xstrfmt("%d", v);
else else
@@ -674,6 +676,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
char *value = NULL; char *value = NULL;
int flags = 0; int flags = 0;
int ret = 0; int ret = 0;
struct key_value_info default_kvi = KVI_INIT;
given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); 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) { else if (actions == ACTION_SET) {
check_write(); check_write();
check_argc(argc, 2, 2); 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); ret = git_config_set_in_file_gently(given_config_source.file, argv[0], value);
if (ret == CONFIG_NOTHING_SET) if (ret == CONFIG_NOTHING_SET)
error(_("cannot overwrite multiple values with a single value\n" 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) { else if (actions == ACTION_SET_ALL) {
check_write(); check_write();
check_argc(argc, 2, 3); 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, ret = git_config_set_multivar_in_file_gently(given_config_source.file,
argv[0], value, argv[2], argv[0], value, argv[2],
flags); flags);
@@ -908,7 +911,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
else if (actions == ACTION_ADD) { else if (actions == ACTION_ADD) {
check_write(); check_write();
check_argc(argc, 2, 2); 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, ret = git_config_set_multivar_in_file_gently(given_config_source.file,
argv[0], value, argv[0], value,
CONFIG_REGEX_NONE, CONFIG_REGEX_NONE,
@@ -917,7 +920,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
else if (actions == ACTION_REPLACE_ALL) { else if (actions == ACTION_REPLACE_ALL) {
check_write(); check_write();
check_argc(argc, 2, 3); 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, ret = git_config_set_multivar_in_file_gently(given_config_source.file,
argv[0], value, argv[2], argv[0], value, argv[2],
flags | CONFIG_FLAGS_MULTI_REPLACE); flags | CONFIG_FLAGS_MULTI_REPLACE);

View File

@@ -137,7 +137,7 @@ static int git_fetch_config(const char *k, const char *v,
} }
if (!strcmp(k, "submodule.fetchjobs")) { 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; return 0;
} else if (!strcmp(k, "fetch.recursesubmodules")) { } else if (!strcmp(k, "fetch.recursesubmodules")) {
fetch_config->recurse_submodules = parse_fetch_recurse_submodules_arg(k, v); 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")) { 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) if (fetch_config->parallel < 0)
die(_("fetch.parallel cannot be negative")); die(_("fetch.parallel cannot be negative"));
if (!fetch_config->parallel) if (!fetch_config->parallel)

View File

@@ -41,7 +41,7 @@ static int fsmonitor_config(const char *var, const char *value,
const struct config_context *ctx, void *cb) const struct config_context *ctx, void *cb)
{ {
if (!strcmp(var, FSMONITOR__IPC_THREADS)) { 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) if (i < 1)
return error(_("value of '%s' out of range: %d"), return error(_("value of '%s' out of range: %d"),
FSMONITOR__IPC_THREADS, i); FSMONITOR__IPC_THREADS, i);
@@ -50,7 +50,7 @@ static int fsmonitor_config(const char *var, const char *value,
} }
if (!strcmp(var, FSMONITOR__START_TIMEOUT)) { 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) if (i < 0)
return error(_("value of '%s' out of range: %d"), return error(_("value of '%s' out of range: %d"),
FSMONITOR__START_TIMEOUT, i); FSMONITOR__START_TIMEOUT, i);
@@ -60,7 +60,7 @@ static int fsmonitor_config(const char *var, const char *value,
if (!strcmp(var, FSMONITOR__ANNOUNCE_STARTUP)) { if (!strcmp(var, FSMONITOR__ANNOUNCE_STARTUP)) {
int is_bool; 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) if (i < 0)
return error(_("value of '%s' not bool or int: %d"), return error(_("value of '%s' not bool or int: %d"),
var, i); var, i);

View File

@@ -301,7 +301,7 @@ static int grep_cmd_config(const char *var, const char *value,
st = -1; st = -1;
if (!strcmp(var, "grep.threads")) { 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) if (num_threads < 0)
die(_("invalid number of threads specified (%d) for %s"), die(_("invalid number of threads specified (%d) for %s"),
num_threads, var); num_threads, var);

View File

@@ -1587,13 +1587,13 @@ static int git_index_pack_config(const char *k, const char *v,
struct pack_idx_option *opts = cb; struct pack_idx_option *opts = cb;
if (!strcmp(k, "pack.indexversion")) { 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) if (opts->version > 2)
die(_("bad pack.indexVersion=%"PRIu32), opts->version); die(_("bad pack.indexVersion=%"PRIu32), opts->version);
return 0; return 0;
} }
if (!strcmp(k, "pack.threads")) { 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) if (nr_threads < 0)
die(_("invalid number of threads specified (%d)"), die(_("invalid number of threads specified (%d)"),
nr_threads); nr_threads);

View File

@@ -574,7 +574,7 @@ static int git_log_config(const char *var, const char *value,
if (!strcmp(var, "format.subjectprefix")) if (!strcmp(var, "format.subjectprefix"))
return git_config_string(&fmt_patch_subject_prefix, var, value); return git_config_string(&fmt_patch_subject_prefix, var, value);
if (!strcmp(var, "format.filenamemaxlength")) { 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; return 0;
} }
if (!strcmp(var, "format.encodeemailheaders")) { if (!strcmp(var, "format.encodeemailheaders")) {

View File

@@ -3139,23 +3139,23 @@ static int git_pack_config(const char *k, const char *v,
const struct config_context *ctx, void *cb) const struct config_context *ctx, void *cb)
{ {
if (!strcmp(k, "pack.window")) { if (!strcmp(k, "pack.window")) {
window = git_config_int(k, v); window = git_config_int(k, v, ctx->kvi);
return 0; return 0;
} }
if (!strcmp(k, "pack.windowmemory")) { if (!strcmp(k, "pack.windowmemory")) {
window_memory_limit = git_config_ulong(k, v); window_memory_limit = git_config_ulong(k, v, ctx->kvi);
return 0; return 0;
} }
if (!strcmp(k, "pack.depth")) { if (!strcmp(k, "pack.depth")) {
depth = git_config_int(k, v); depth = git_config_int(k, v, ctx->kvi);
return 0; return 0;
} }
if (!strcmp(k, "pack.deltacachesize")) { if (!strcmp(k, "pack.deltacachesize")) {
max_delta_cache_size = git_config_int(k, v); max_delta_cache_size = git_config_int(k, v, ctx->kvi);
return 0; return 0;
} }
if (!strcmp(k, "pack.deltacachelimit")) { if (!strcmp(k, "pack.deltacachelimit")) {
cache_max_small_delta_size = git_config_int(k, v); cache_max_small_delta_size = git_config_int(k, v, ctx->kvi);
return 0; return 0;
} }
if (!strcmp(k, "pack.writebitmaphashcache")) { if (!strcmp(k, "pack.writebitmaphashcache")) {
@@ -3181,7 +3181,7 @@ static int git_pack_config(const char *k, const char *v,
return 0; return 0;
} }
if (!strcmp(k, "pack.threads")) { if (!strcmp(k, "pack.threads")) {
delta_search_threads = git_config_int(k, v); delta_search_threads = git_config_int(k, v, ctx->kvi);
if (delta_search_threads < 0) if (delta_search_threads < 0)
die(_("invalid number of threads specified (%d)"), die(_("invalid number of threads specified (%d)"),
delta_search_threads); delta_search_threads);
@@ -3192,7 +3192,7 @@ static int git_pack_config(const char *k, const char *v,
return 0; return 0;
} }
if (!strcmp(k, "pack.indexversion")) { if (!strcmp(k, "pack.indexversion")) {
pack_idx_opts.version = git_config_int(k, v); pack_idx_opts.version = git_config_int(k, v, ctx->kvi);
if (pack_idx_opts.version > 2) if (pack_idx_opts.version > 2)
die(_("bad pack.indexVersion=%"PRIu32), die(_("bad pack.indexVersion=%"PRIu32),
pack_idx_opts.version); pack_idx_opts.version);

View File

@@ -158,12 +158,12 @@ static int receive_pack_config(const char *var, const char *value,
} }
if (strcmp(var, "receive.unpacklimit") == 0) { if (strcmp(var, "receive.unpacklimit") == 0) {
receive_unpack_limit = git_config_int(var, value); receive_unpack_limit = git_config_int(var, value, ctx->kvi);
return 0; return 0;
} }
if (strcmp(var, "transfer.unpacklimit") == 0) { if (strcmp(var, "transfer.unpacklimit") == 0) {
transfer_unpack_limit = git_config_int(var, value); transfer_unpack_limit = git_config_int(var, value, ctx->kvi);
return 0; return 0;
} }
@@ -231,7 +231,7 @@ static int receive_pack_config(const char *var, const char *value,
return git_config_string(&cert_nonce_seed, var, value); return git_config_string(&cert_nonce_seed, var, value);
if (strcmp(var, "receive.certnonceslop") == 0) { if (strcmp(var, "receive.certnonceslop") == 0) {
nonce_stamp_slop_limit = git_config_ulong(var, value); nonce_stamp_slop_limit = git_config_ulong(var, value, ctx->kvi);
return 0; return 0;
} }
@@ -246,12 +246,12 @@ static int receive_pack_config(const char *var, const char *value,
} }
if (strcmp(var, "receive.keepalive") == 0) { if (strcmp(var, "receive.keepalive") == 0) {
keepalive_in_sec = git_config_int(var, value); keepalive_in_sec = git_config_int(var, value, ctx->kvi);
return 0; return 0;
} }
if (strcmp(var, "receive.maxinputsize") == 0) { if (strcmp(var, "receive.maxinputsize") == 0) {
max_input_size = git_config_int64(var, value); max_input_size = git_config_int64(var, value, ctx->kvi);
return 0; return 0;
} }

View File

@@ -2192,13 +2192,13 @@ static int update_clone_task_finished(int result,
} }
static int git_update_clone_config(const char *var, const char *value, static int git_update_clone_config(const char *var, const char *value,
const struct config_context *ctx UNUSED, const struct config_context *ctx,
void *cb) void *cb)
{ {
int *max_jobs = cb; int *max_jobs = cb;
if (!strcmp(var, "submodule.fetchjobs")) if (!strcmp(var, "submodule.fetchjobs"))
*max_jobs = parse_submodule_fetchjobs(var, value); *max_jobs = parse_submodule_fetchjobs(var, value, ctx->kvi);
return 0; return 0;
} }

156
config.c
View File

@@ -73,18 +73,8 @@ struct config_reader {
* *
* The "source" variable will be non-NULL only when we are actually * The "source" variable will be non-NULL only when we are actually
* parsing a real config source (file, blob, cmdline, etc). * parsing a real config source (file, blob, cmdline, etc).
*
* The "config_kvi" variable will be non-NULL only when we are feeding
* cached config from a configset into a callback.
*
* They cannot be non-NULL at the same time. If they are both NULL, then
* we aren't parsing anything (and depending on the function looking at
* the variables, it's either a bug for it to be called in the first
* place, or it's a function which can be reused for non-config
* purposes, and should fall back to some sane behavior).
*/ */
struct config_source *source; struct config_source *source;
struct key_value_info *config_kvi;
}; };
/* /*
* Where possible, prefer to accept "struct config_reader" as an arg than to use * Where possible, prefer to accept "struct config_reader" as an arg than to use
@@ -96,8 +86,6 @@ static struct config_reader the_reader;
static inline void config_reader_push_source(struct config_reader *reader, static inline void config_reader_push_source(struct config_reader *reader,
struct config_source *top) struct config_source *top)
{ {
if (reader->config_kvi)
BUG("source should not be set while iterating a config set");
top->prev = reader->source; top->prev = reader->source;
reader->source = top; reader->source = top;
} }
@@ -112,12 +100,6 @@ static inline struct config_source *config_reader_pop_source(struct config_reade
return ret; return ret;
} }
static inline void config_reader_set_kvi(struct config_reader *reader,
struct key_value_info *kvi)
{
reader->config_kvi = kvi;
}
static int pack_compression_seen; static int pack_compression_seen;
static int zlib_compression_seen; static int zlib_compression_seen;
@@ -1346,80 +1328,78 @@ int git_parse_ssize_t(const char *value, ssize_t *ret)
return 1; return 1;
} }
static int reader_config_name(struct config_reader *reader, const char **out);
static int reader_origin_type(struct config_reader *reader,
enum config_origin_type *type);
NORETURN NORETURN
static void die_bad_number(struct config_reader *reader, const char *name, static void die_bad_number(const char *name, const char *value,
const char *value) const struct key_value_info *kvi)
{ {
const char *error_type = (errno == ERANGE) ? const char *error_type = (errno == ERANGE) ?
N_("out of range") : N_("invalid unit"); N_("out of range") : N_("invalid unit");
const char *bad_numeric = N_("bad numeric config value '%s' for '%s': %s"); const char *bad_numeric = N_("bad numeric config value '%s' for '%s': %s");
const char *config_name = NULL;
enum config_origin_type config_origin = CONFIG_ORIGIN_UNKNOWN; if (!kvi)
BUG("kvi should not be NULL");
if (!value) if (!value)
value = ""; value = "";
/* Ignoring the return value is okay since we handle missing values. */ if (!kvi->filename)
reader_config_name(reader, &config_name);
reader_origin_type(reader, &config_origin);
if (!config_name)
die(_(bad_numeric), value, name, _(error_type)); die(_(bad_numeric), value, name, _(error_type));
switch (config_origin) { switch (kvi->origin_type) {
case CONFIG_ORIGIN_BLOB: case CONFIG_ORIGIN_BLOB:
die(_("bad numeric config value '%s' for '%s' in blob %s: %s"), die(_("bad numeric config value '%s' for '%s' in blob %s: %s"),
value, name, config_name, _(error_type)); value, name, kvi->filename, _(error_type));
case CONFIG_ORIGIN_FILE: case CONFIG_ORIGIN_FILE:
die(_("bad numeric config value '%s' for '%s' in file %s: %s"), die(_("bad numeric config value '%s' for '%s' in file %s: %s"),
value, name, config_name, _(error_type)); value, name, kvi->filename, _(error_type));
case CONFIG_ORIGIN_STDIN: case CONFIG_ORIGIN_STDIN:
die(_("bad numeric config value '%s' for '%s' in standard input: %s"), die(_("bad numeric config value '%s' for '%s' in standard input: %s"),
value, name, _(error_type)); value, name, _(error_type));
case CONFIG_ORIGIN_SUBMODULE_BLOB: case CONFIG_ORIGIN_SUBMODULE_BLOB:
die(_("bad numeric config value '%s' for '%s' in submodule-blob %s: %s"), die(_("bad numeric config value '%s' for '%s' in submodule-blob %s: %s"),
value, name, config_name, _(error_type)); value, name, kvi->filename, _(error_type));
case CONFIG_ORIGIN_CMDLINE: case CONFIG_ORIGIN_CMDLINE:
die(_("bad numeric config value '%s' for '%s' in command line %s: %s"), die(_("bad numeric config value '%s' for '%s' in command line %s: %s"),
value, name, config_name, _(error_type)); value, name, kvi->filename, _(error_type));
default: default:
die(_("bad numeric config value '%s' for '%s' in %s: %s"), die(_("bad numeric config value '%s' for '%s' in %s: %s"),
value, name, config_name, _(error_type)); value, name, kvi->filename, _(error_type));
} }
} }
int git_config_int(const char *name, const char *value) int git_config_int(const char *name, const char *value,
const struct key_value_info *kvi)
{ {
int ret; int ret;
if (!git_parse_int(value, &ret)) if (!git_parse_int(value, &ret))
die_bad_number(&the_reader, name, value); die_bad_number(name, value, kvi);
return ret; return ret;
} }
int64_t git_config_int64(const char *name, const char *value) int64_t git_config_int64(const char *name, const char *value,
const struct key_value_info *kvi)
{ {
int64_t ret; int64_t ret;
if (!git_parse_int64(value, &ret)) if (!git_parse_int64(value, &ret))
die_bad_number(&the_reader, name, value); die_bad_number(name, value, kvi);
return ret; return ret;
} }
unsigned long git_config_ulong(const char *name, const char *value) unsigned long git_config_ulong(const char *name, const char *value,
const struct key_value_info *kvi)
{ {
unsigned long ret; unsigned long ret;
if (!git_parse_ulong(value, &ret)) if (!git_parse_ulong(value, &ret))
die_bad_number(&the_reader, name, value); die_bad_number(name, value, kvi);
return ret; return ret;
} }
ssize_t git_config_ssize_t(const char *name, const char *value) ssize_t git_config_ssize_t(const char *name, const char *value,
const struct key_value_info *kvi)
{ {
ssize_t ret; ssize_t ret;
if (!git_parse_ssize_t(value, &ret)) if (!git_parse_ssize_t(value, &ret))
die_bad_number(&the_reader, name, value); die_bad_number(name, value, kvi);
return ret; return ret;
} }
@@ -1524,7 +1504,8 @@ int git_parse_maybe_bool(const char *value)
return -1; return -1;
} }
int git_config_bool_or_int(const char *name, const char *value, int *is_bool) int git_config_bool_or_int(const char *name, const char *value,
const struct key_value_info *kvi, int *is_bool)
{ {
int v = git_parse_maybe_bool_text(value); int v = git_parse_maybe_bool_text(value);
if (0 <= v) { if (0 <= v) {
@@ -1532,7 +1513,7 @@ int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
return v; return v;
} }
*is_bool = 0; *is_bool = 0;
return git_config_int(name, value); return git_config_int(name, value, kvi);
} }
int git_config_bool(const char *name, const char *value) int git_config_bool(const char *name, const char *value)
@@ -1658,7 +1639,7 @@ static int git_default_core_config(const char *var, const char *value,
else if (!git_parse_maybe_bool_text(value)) else if (!git_parse_maybe_bool_text(value))
default_abbrev = the_hash_algo->hexsz; default_abbrev = the_hash_algo->hexsz;
else { else {
int abbrev = git_config_int(var, value); int abbrev = git_config_int(var, value, ctx->kvi);
if (abbrev < minimum_abbrev || abbrev > the_hash_algo->hexsz) if (abbrev < minimum_abbrev || abbrev > the_hash_algo->hexsz)
return error(_("abbrev length out of range: %d"), abbrev); return error(_("abbrev length out of range: %d"), abbrev);
default_abbrev = abbrev; default_abbrev = abbrev;
@@ -1670,7 +1651,7 @@ static int git_default_core_config(const char *var, const char *value,
return set_disambiguate_hint_config(var, value); return set_disambiguate_hint_config(var, value);
if (!strcmp(var, "core.loosecompression")) { if (!strcmp(var, "core.loosecompression")) {
int level = git_config_int(var, value); int level = git_config_int(var, value, ctx->kvi);
if (level == -1) if (level == -1)
level = Z_DEFAULT_COMPRESSION; level = Z_DEFAULT_COMPRESSION;
else if (level < 0 || level > Z_BEST_COMPRESSION) else if (level < 0 || level > Z_BEST_COMPRESSION)
@@ -1681,7 +1662,7 @@ static int git_default_core_config(const char *var, const char *value,
} }
if (!strcmp(var, "core.compression")) { if (!strcmp(var, "core.compression")) {
int level = git_config_int(var, value); int level = git_config_int(var, value, ctx->kvi);
if (level == -1) if (level == -1)
level = Z_DEFAULT_COMPRESSION; level = Z_DEFAULT_COMPRESSION;
else if (level < 0 || level > Z_BEST_COMPRESSION) else if (level < 0 || level > Z_BEST_COMPRESSION)
@@ -1695,7 +1676,7 @@ static int git_default_core_config(const char *var, const char *value,
if (!strcmp(var, "core.packedgitwindowsize")) { if (!strcmp(var, "core.packedgitwindowsize")) {
int pgsz_x2 = getpagesize() * 2; int pgsz_x2 = getpagesize() * 2;
packed_git_window_size = git_config_ulong(var, value); packed_git_window_size = git_config_ulong(var, value, ctx->kvi);
/* This value must be multiple of (pagesize * 2) */ /* This value must be multiple of (pagesize * 2) */
packed_git_window_size /= pgsz_x2; packed_git_window_size /= pgsz_x2;
@@ -1706,17 +1687,17 @@ static int git_default_core_config(const char *var, const char *value,
} }
if (!strcmp(var, "core.bigfilethreshold")) { if (!strcmp(var, "core.bigfilethreshold")) {
big_file_threshold = git_config_ulong(var, value); big_file_threshold = git_config_ulong(var, value, ctx->kvi);
return 0; return 0;
} }
if (!strcmp(var, "core.packedgitlimit")) { if (!strcmp(var, "core.packedgitlimit")) {
packed_git_limit = git_config_ulong(var, value); packed_git_limit = git_config_ulong(var, value, ctx->kvi);
return 0; return 0;
} }
if (!strcmp(var, "core.deltabasecachelimit")) { if (!strcmp(var, "core.deltabasecachelimit")) {
delta_base_cache_limit = git_config_ulong(var, value); delta_base_cache_limit = git_config_ulong(var, value, ctx->kvi);
return 0; return 0;
} }
@@ -1995,12 +1976,12 @@ int git_default_config(const char *var, const char *value,
} }
if (!strcmp(var, "pack.packsizelimit")) { if (!strcmp(var, "pack.packsizelimit")) {
pack_size_limit_cfg = git_config_ulong(var, value); pack_size_limit_cfg = git_config_ulong(var, value, ctx->kvi);
return 0; return 0;
} }
if (!strcmp(var, "pack.compression")) { if (!strcmp(var, "pack.compression")) {
int level = git_config_int(var, value); int level = git_config_int(var, value, ctx->kvi);
if (level == -1) if (level == -1)
level = Z_DEFAULT_COMPRESSION; level = Z_DEFAULT_COMPRESSION;
else if (level < 0 || level > Z_BEST_COMPRESSION) else if (level < 0 || level > Z_BEST_COMPRESSION)
@@ -2344,13 +2325,11 @@ static void configset_iter(struct config_reader *reader, struct config_set *set,
value_index = list->items[i].value_index; value_index = list->items[i].value_index;
values = &entry->value_list; values = &entry->value_list;
config_reader_set_kvi(reader, values->items[value_index].util);
ctx.kvi = values->items[value_index].util; ctx.kvi = values->items[value_index].util;
if (fn(entry->key, values->items[value_index].string, &ctx, data) < 0) if (fn(entry->key, values->items[value_index].string, &ctx, data) < 0)
git_die_config_linenr(entry->key, git_die_config_linenr(entry->key,
ctx.kvi->filename, ctx.kvi->filename,
ctx.kvi->linenr); ctx.kvi->linenr);
config_reader_set_kvi(reader, NULL);
} }
} }
@@ -2536,11 +2515,12 @@ int git_configset_add_file(struct config_set *set, const char *filename)
return git_config_from_file(config_set_callback, filename, &data); return git_config_from_file(config_set_callback, filename, &data);
} }
int git_configset_get_value(struct config_set *set, const char *key, const char **value) int git_configset_get_value(struct config_set *set, const char *key,
const char **value, struct key_value_info *kvi)
{ {
const struct string_list *values = NULL; const struct string_list *values = NULL;
int ret; int ret;
struct string_list_item item;
/* /*
* Follows "last one wins" semantic, i.e., if there are multiple matches for the * Follows "last one wins" semantic, i.e., if there are multiple matches for the
* queried key in the files of the configset, the value returned will be the last * queried key in the files of the configset, the value returned will be the last
@@ -2550,7 +2530,10 @@ int git_configset_get_value(struct config_set *set, const char *key, const char
return ret; return ret;
assert(values->nr > 0); assert(values->nr > 0);
*value = values->items[values->nr - 1].string; item = values->items[values->nr - 1];
*value = item.string;
if (kvi)
*kvi = *((struct key_value_info *)item.util);
return 0; return 0;
} }
@@ -2603,7 +2586,7 @@ int git_configset_get(struct config_set *set, const char *key)
int git_configset_get_string(struct config_set *set, const char *key, char **dest) int git_configset_get_string(struct config_set *set, const char *key, char **dest)
{ {
const char *value; const char *value;
if (!git_configset_get_value(set, key, &value)) if (!git_configset_get_value(set, key, &value, NULL))
return git_config_string((const char **)dest, key, value); return git_config_string((const char **)dest, key, value);
else else
return 1; return 1;
@@ -2613,7 +2596,7 @@ static int git_configset_get_string_tmp(struct config_set *set, const char *key,
const char **dest) const char **dest)
{ {
const char *value; const char *value;
if (!git_configset_get_value(set, key, &value)) { if (!git_configset_get_value(set, key, &value, NULL)) {
if (!value) if (!value)
return config_error_nonbool(key); return config_error_nonbool(key);
*dest = value; *dest = value;
@@ -2626,8 +2609,10 @@ static int git_configset_get_string_tmp(struct config_set *set, const char *key,
int git_configset_get_int(struct config_set *set, const char *key, int *dest) int git_configset_get_int(struct config_set *set, const char *key, int *dest)
{ {
const char *value; const char *value;
if (!git_configset_get_value(set, key, &value)) { struct key_value_info kvi;
*dest = git_config_int(key, value);
if (!git_configset_get_value(set, key, &value, &kvi)) {
*dest = git_config_int(key, value, &kvi);
return 0; return 0;
} else } else
return 1; return 1;
@@ -2636,8 +2621,10 @@ int git_configset_get_int(struct config_set *set, const char *key, int *dest)
int git_configset_get_ulong(struct config_set *set, const char *key, unsigned long *dest) int git_configset_get_ulong(struct config_set *set, const char *key, unsigned long *dest)
{ {
const char *value; const char *value;
if (!git_configset_get_value(set, key, &value)) { struct key_value_info kvi;
*dest = git_config_ulong(key, value);
if (!git_configset_get_value(set, key, &value, &kvi)) {
*dest = git_config_ulong(key, value, &kvi);
return 0; return 0;
} else } else
return 1; return 1;
@@ -2646,7 +2633,7 @@ int git_configset_get_ulong(struct config_set *set, const char *key, unsigned lo
int git_configset_get_bool(struct config_set *set, const char *key, int *dest) int git_configset_get_bool(struct config_set *set, const char *key, int *dest)
{ {
const char *value; const char *value;
if (!git_configset_get_value(set, key, &value)) { if (!git_configset_get_value(set, key, &value, NULL)) {
*dest = git_config_bool(key, value); *dest = git_config_bool(key, value);
return 0; return 0;
} else } else
@@ -2657,8 +2644,10 @@ int git_configset_get_bool_or_int(struct config_set *set, const char *key,
int *is_bool, int *dest) int *is_bool, int *dest)
{ {
const char *value; const char *value;
if (!git_configset_get_value(set, key, &value)) { struct key_value_info kvi;
*dest = git_config_bool_or_int(key, value, is_bool);
if (!git_configset_get_value(set, key, &value, &kvi)) {
*dest = git_config_bool_or_int(key, value, &kvi, is_bool);
return 0; return 0;
} else } else
return 1; return 1;
@@ -2667,7 +2656,7 @@ int git_configset_get_bool_or_int(struct config_set *set, const char *key,
int git_configset_get_maybe_bool(struct config_set *set, const char *key, int *dest) int git_configset_get_maybe_bool(struct config_set *set, const char *key, int *dest)
{ {
const char *value; const char *value;
if (!git_configset_get_value(set, key, &value)) { if (!git_configset_get_value(set, key, &value, NULL)) {
*dest = git_parse_maybe_bool(value); *dest = git_parse_maybe_bool(value);
if (*dest == -1) if (*dest == -1)
return -1; return -1;
@@ -2679,7 +2668,7 @@ int git_configset_get_maybe_bool(struct config_set *set, const char *key, int *d
int git_configset_get_pathname(struct config_set *set, const char *key, const char **dest) int git_configset_get_pathname(struct config_set *set, const char *key, const char **dest)
{ {
const char *value; const char *value;
if (!git_configset_get_value(set, key, &value)) if (!git_configset_get_value(set, key, &value, NULL))
return git_config_pathname(dest, key, value); return git_config_pathname(dest, key, value);
else else
return 1; return 1;
@@ -2749,7 +2738,7 @@ int repo_config_get_value(struct repository *repo,
const char *key, const char **value) const char *key, const char **value)
{ {
git_config_check_init(repo); git_config_check_init(repo);
return git_configset_get_value(repo->config, key, value); return git_configset_get_value(repo->config, key, value, NULL);
} }
int repo_config_get_value_multi(struct repository *repo, const char *key, int repo_config_get_value_multi(struct repository *repo, const char *key,
@@ -3989,18 +3978,6 @@ int parse_config_key(const char *var,
return 0; return 0;
} }
static int reader_origin_type(struct config_reader *reader,
enum config_origin_type *type)
{
if (the_reader.config_kvi)
*type = reader->config_kvi->origin_type;
else if(the_reader.source)
*type = reader->source->origin_type;
else
return 1;
return 0;
}
const char *config_origin_type_name(enum config_origin_type type) const char *config_origin_type_name(enum config_origin_type type)
{ {
switch (type) { switch (type) {
@@ -4039,17 +4016,6 @@ const char *config_scope_name(enum config_scope scope)
} }
} }
static int reader_config_name(struct config_reader *reader, const char **out)
{
if (the_reader.config_kvi)
*out = reader->config_kvi->filename;
else if (the_reader.source)
*out = reader->source->name;
else
return 1;
return 0;
}
int lookup_config(const char **mapping, int nr_mapping, const char *var) int lookup_config(const char **mapping, int nr_mapping, const char *var)
{ {
int i; int i;

View File

@@ -249,22 +249,26 @@ int git_parse_maybe_bool(const char *);
* Parse the string to an integer, including unit factors. Dies on error; * Parse the string to an integer, including unit factors. Dies on error;
* otherwise, returns the parsed result. * otherwise, returns the parsed result.
*/ */
int git_config_int(const char *, const char *); int git_config_int(const char *, const char *, const struct key_value_info *);
int64_t git_config_int64(const char *, const char *); int64_t git_config_int64(const char *, const char *,
const struct key_value_info *);
/** /**
* Identical to `git_config_int`, but for unsigned longs. * Identical to `git_config_int`, but for unsigned longs.
*/ */
unsigned long git_config_ulong(const char *, const char *); unsigned long git_config_ulong(const char *, const char *,
const struct key_value_info *);
ssize_t git_config_ssize_t(const char *, const char *); ssize_t git_config_ssize_t(const char *, const char *,
const struct key_value_info *);
/** /**
* Same as `git_config_bool`, except that integers are returned as-is, and * Same as `git_config_bool`, except that integers are returned as-is, and
* an `is_bool` flag is unset. * an `is_bool` flag is unset.
*/ */
int git_config_bool_or_int(const char *, const char *, int *); int git_config_bool_or_int(const char *, const char *,
const struct key_value_info *, int *);
/** /**
* Parse a string into a boolean value, respecting keywords like "true" and * Parse a string into a boolean value, respecting keywords like "true" and
@@ -529,7 +533,8 @@ int git_configset_get(struct config_set *cs, const char *key);
* touching `value`. The caller should not free or modify `value`, as it * touching `value`. The caller should not free or modify `value`, as it
* is owned by the cache. * is owned by the cache.
*/ */
int git_configset_get_value(struct config_set *cs, const char *key, const char **dest); int git_configset_get_value(struct config_set *cs, const char *key,
const char **dest, struct key_value_info *kvi);
int git_configset_get_string(struct config_set *cs, const char *key, char **dest); int git_configset_get_string(struct config_set *cs, const char *key, char **dest);
int git_configset_get_int(struct config_set *cs, const char *key, int *dest); int git_configset_get_int(struct config_set *cs, const char *key, int *dest);

View File

@@ -0,0 +1,27 @@
@@
identifier C1, C2, C3;
@@
(
(
git_config_int
|
git_config_int64
|
git_config_ulong
|
git_config_ssize_t
)
(C1, C2
+ , ctx->kvi
)
|
(
git_configset_get_value
|
git_config_bool_or_int
)
(C1, C2
+ , ctx->kvi
, C3
)
)

9
diff.c
View File

@@ -379,13 +379,14 @@ int git_diff_ui_config(const char *var, const char *value,
return 0; return 0;
} }
if (!strcmp(var, "diff.context")) { if (!strcmp(var, "diff.context")) {
diff_context_default = git_config_int(var, value); diff_context_default = git_config_int(var, value, ctx->kvi);
if (diff_context_default < 0) if (diff_context_default < 0)
return -1; return -1;
return 0; return 0;
} }
if (!strcmp(var, "diff.interhunkcontext")) { if (!strcmp(var, "diff.interhunkcontext")) {
diff_interhunk_context_default = git_config_int(var, value); diff_interhunk_context_default = git_config_int(var, value,
ctx->kvi);
if (diff_interhunk_context_default < 0) if (diff_interhunk_context_default < 0)
return -1; return -1;
return 0; return 0;
@@ -411,7 +412,7 @@ int git_diff_ui_config(const char *var, const char *value,
return 0; return 0;
} }
if (!strcmp(var, "diff.statgraphwidth")) { if (!strcmp(var, "diff.statgraphwidth")) {
diff_stat_graph_width = git_config_int(var, value); diff_stat_graph_width = git_config_int(var, value, ctx->kvi);
return 0; return 0;
} }
if (!strcmp(var, "diff.external")) if (!strcmp(var, "diff.external"))
@@ -450,7 +451,7 @@ int git_diff_basic_config(const char *var, const char *value,
const char *name; const char *name;
if (!strcmp(var, "diff.renamelimit")) { if (!strcmp(var, "diff.renamelimit")) {
diff_rename_limit_default = git_config_int(var, value); diff_rename_limit_default = git_config_int(var, value, ctx->kvi);
return 0; return 0;
} }

View File

@@ -25,7 +25,7 @@ int fmt_merge_msg_config(const char *key, const char *value,
{ {
if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) { if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) {
int is_bool; int is_bool;
merge_log_config = git_config_bool_or_int(key, value, &is_bool); merge_log_config = git_config_bool_or_int(key, value, ctx->kvi, &is_bool);
if (!is_bool && merge_log_config < 0) if (!is_bool && merge_log_config < 0)
return error("%s: negative length %s", key, value); return error("%s: negative length %s", key, value);
if (is_bool && merge_log_config) if (is_bool && merge_log_config)

4
help.c
View File

@@ -545,7 +545,7 @@ static struct cmdnames aliases;
#define AUTOCORRECT_IMMEDIATELY (-1) #define AUTOCORRECT_IMMEDIATELY (-1)
static int git_unknown_cmd_config(const char *var, const char *value, static int git_unknown_cmd_config(const char *var, const char *value,
const struct config_context *ctx UNUSED, const struct config_context *ctx,
void *cb UNUSED) void *cb UNUSED)
{ {
const char *p; const char *p;
@@ -560,7 +560,7 @@ static int git_unknown_cmd_config(const char *var, const char *value,
} else if (!strcmp(value, "prompt")) { } else if (!strcmp(value, "prompt")) {
autocorrect = AUTOCORRECT_PROMPT; autocorrect = AUTOCORRECT_PROMPT;
} else { } else {
int v = git_config_int(var, value); int v = git_config_int(var, value, ctx->kvi);
autocorrect = (v < 0) autocorrect = (v < 0)
? AUTOCORRECT_IMMEDIATELY : v; ? AUTOCORRECT_IMMEDIATELY : v;
} }

10
http.c
View File

@@ -414,21 +414,21 @@ static int http_options(const char *var, const char *value,
} }
if (!strcmp("http.minsessions", var)) { if (!strcmp("http.minsessions", var)) {
min_curl_sessions = git_config_int(var, value); min_curl_sessions = git_config_int(var, value, ctx->kvi);
if (min_curl_sessions > 1) if (min_curl_sessions > 1)
min_curl_sessions = 1; min_curl_sessions = 1;
return 0; return 0;
} }
if (!strcmp("http.maxrequests", var)) { if (!strcmp("http.maxrequests", var)) {
max_requests = git_config_int(var, value); max_requests = git_config_int(var, value, ctx->kvi);
return 0; return 0;
} }
if (!strcmp("http.lowspeedlimit", var)) { if (!strcmp("http.lowspeedlimit", var)) {
curl_low_speed_limit = (long)git_config_int(var, value); curl_low_speed_limit = (long)git_config_int(var, value, ctx->kvi);
return 0; return 0;
} }
if (!strcmp("http.lowspeedtime", var)) { if (!strcmp("http.lowspeedtime", var)) {
curl_low_speed_time = (long)git_config_int(var, value); curl_low_speed_time = (long)git_config_int(var, value, ctx->kvi);
return 0; return 0;
} }
@@ -464,7 +464,7 @@ static int http_options(const char *var, const char *value,
} }
if (!strcmp("http.postbuffer", var)) { if (!strcmp("http.postbuffer", var)) {
http_post_buffer = git_config_ssize_t(var, value); http_post_buffer = git_config_ssize_t(var, value, ctx->kvi);
if (http_post_buffer < 0) if (http_post_buffer < 0)
warning(_("negative value for http.postBuffer; defaulting to %d"), LARGE_PACKET_MAX); warning(_("negative value for http.postBuffer; defaulting to %d"), LARGE_PACKET_MAX);
if (http_post_buffer < LARGE_PACKET_MAX) if (http_post_buffer < LARGE_PACKET_MAX)

View File

@@ -1342,7 +1342,7 @@ static int git_imap_config(const char *var, const char *val,
else if (!strcmp("imap.authmethod", var)) else if (!strcmp("imap.authmethod", var))
return git_config_string(&server.auth_method, var, val); return git_config_string(&server.auth_method, var, val);
else if (!strcmp("imap.port", var)) else if (!strcmp("imap.port", var))
server.port = git_config_int(var, val); server.port = git_config_int(var, val, ctx->kvi);
else if (!strcmp("imap.host", var)) { else if (!strcmp("imap.host", var)) {
if (!val) { if (!val) {
git_die_config("imap.host", "Missing value for 'imap.host'"); git_die_config("imap.host", "Missing value for 'imap.host'");

View File

@@ -2883,7 +2883,7 @@ static int git_config_string_dup(char **dest,
} }
static int populate_opts_cb(const char *key, const char *value, static int populate_opts_cb(const char *key, const char *value,
const struct config_context *ctx UNUSED, const struct config_context *ctx,
void *data) void *data)
{ {
struct replay_opts *opts = data; struct replay_opts *opts = data;
@@ -2892,26 +2892,26 @@ static int populate_opts_cb(const char *key, const char *value,
if (!value) if (!value)
error_flag = 0; error_flag = 0;
else if (!strcmp(key, "options.no-commit")) else if (!strcmp(key, "options.no-commit"))
opts->no_commit = git_config_bool_or_int(key, value, &error_flag); opts->no_commit = git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.edit")) else if (!strcmp(key, "options.edit"))
opts->edit = git_config_bool_or_int(key, value, &error_flag); opts->edit = git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.allow-empty")) else if (!strcmp(key, "options.allow-empty"))
opts->allow_empty = opts->allow_empty =
git_config_bool_or_int(key, value, &error_flag); git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.allow-empty-message")) else if (!strcmp(key, "options.allow-empty-message"))
opts->allow_empty_message = opts->allow_empty_message =
git_config_bool_or_int(key, value, &error_flag); git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.keep-redundant-commits")) else if (!strcmp(key, "options.keep-redundant-commits"))
opts->keep_redundant_commits = opts->keep_redundant_commits =
git_config_bool_or_int(key, value, &error_flag); git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.signoff")) else if (!strcmp(key, "options.signoff"))
opts->signoff = git_config_bool_or_int(key, value, &error_flag); opts->signoff = git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.record-origin")) else if (!strcmp(key, "options.record-origin"))
opts->record_origin = git_config_bool_or_int(key, value, &error_flag); opts->record_origin = git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.allow-ff")) else if (!strcmp(key, "options.allow-ff"))
opts->allow_ff = git_config_bool_or_int(key, value, &error_flag); opts->allow_ff = git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.mainline")) else if (!strcmp(key, "options.mainline"))
opts->mainline = git_config_int(key, value); opts->mainline = git_config_int(key, value, ctx->kvi);
else if (!strcmp(key, "options.strategy")) else if (!strcmp(key, "options.strategy"))
git_config_string_dup(&opts->strategy, key, value); git_config_string_dup(&opts->strategy, key, value);
else if (!strcmp(key, "options.gpg-sign")) else if (!strcmp(key, "options.gpg-sign"))
@@ -2920,7 +2920,7 @@ static int populate_opts_cb(const char *key, const char *value,
strvec_push(&opts->xopts, value); strvec_push(&opts->xopts, value);
} else if (!strcmp(key, "options.allow-rerere-auto")) } else if (!strcmp(key, "options.allow-rerere-auto"))
opts->allow_rerere_auto = opts->allow_rerere_auto =
git_config_bool_or_int(key, value, &error_flag) ? git_config_bool_or_int(key, value, ctx->kvi, &error_flag) ?
RERERE_AUTOUPDATE : RERERE_NOAUTOUPDATE; RERERE_AUTOUPDATE : RERERE_NOAUTOUPDATE;
else if (!strcmp(key, "options.default-msg-cleanup")) { else if (!strcmp(key, "options.default-msg-cleanup")) {
opts->explicit_cleanup = 1; opts->explicit_cleanup = 1;

View File

@@ -597,7 +597,7 @@ static int check_repo_format(const char *var, const char *value,
const char *ext; const char *ext;
if (strcmp(var, "core.repositoryformatversion") == 0) if (strcmp(var, "core.repositoryformatversion") == 0)
data->version = git_config_int(var, value); data->version = git_config_int(var, value, ctx->kvi);
else if (skip_prefix(var, "extensions.", &ext)) { else if (skip_prefix(var, "extensions.", &ext)) {
switch (handle_extension_v0(var, value, ext, data)) { switch (handle_extension_v0(var, value, ext, data)) {
case EXTENSION_ERROR: case EXTENSION_ERROR:

View File

@@ -304,9 +304,10 @@ static int parse_fetch_recurse(const char *opt, const char *arg,
} }
} }
int parse_submodule_fetchjobs(const char *var, const char *value) int parse_submodule_fetchjobs(const char *var, const char *value,
const struct key_value_info *kvi)
{ {
int fetchjobs = git_config_int(var, value); int fetchjobs = git_config_int(var, value, kvi);
if (fetchjobs < 0) if (fetchjobs < 0)
die(_("negative values not allowed for submodule.fetchJobs")); die(_("negative values not allowed for submodule.fetchJobs"));
if (!fetchjobs) if (!fetchjobs)
@@ -849,14 +850,14 @@ struct fetch_config {
}; };
static int gitmodules_fetch_config(const char *var, const char *value, static int gitmodules_fetch_config(const char *var, const char *value,
const struct config_context *ctx UNUSED, const struct config_context *ctx,
void *cb) void *cb)
{ {
struct fetch_config *config = cb; struct fetch_config *config = cb;
if (!strcmp(var, "submodule.fetchjobs")) { if (!strcmp(var, "submodule.fetchjobs")) {
if (config->max_children) if (config->max_children)
*(config->max_children) = *(config->max_children) =
parse_submodule_fetchjobs(var, value); parse_submodule_fetchjobs(var, value, ctx->kvi);
return 0; return 0;
} else if (!strcmp(var, "fetch.recursesubmodules")) { } else if (!strcmp(var, "fetch.recursesubmodules")) {
if (config->recurse_submodules) if (config->recurse_submodules)
@@ -878,12 +879,12 @@ void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules)
} }
static int gitmodules_update_clone_config(const char *var, const char *value, static int gitmodules_update_clone_config(const char *var, const char *value,
const struct config_context *ctx UNUSED, const struct config_context *ctx,
void *cb) void *cb)
{ {
int *max_jobs = cb; int *max_jobs = cb;
if (!strcmp(var, "submodule.fetchjobs")) if (!strcmp(var, "submodule.fetchjobs"))
*max_jobs = parse_submodule_fetchjobs(var, value); *max_jobs = parse_submodule_fetchjobs(var, value, ctx->kvi);
return 0; return 0;
} }

View File

@@ -50,7 +50,8 @@ struct repository;
void submodule_cache_free(struct submodule_cache *cache); void submodule_cache_free(struct submodule_cache *cache);
int parse_submodule_fetchjobs(const char *var, const char *value); int parse_submodule_fetchjobs(const char *var, const char *value,
const struct key_value_info *kvi);
int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg); int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);
struct option; struct option;
int option_fetch_parse_recurse_submodules(const struct option *opt, int option_fetch_parse_recurse_submodules(const struct option *opt,

View File

@@ -63,12 +63,12 @@ static int iterate_cb(const char *var, const char *value,
} }
static int parse_int_cb(const char *var, const char *value, static int parse_int_cb(const char *var, const char *value,
const struct config_context *ctx UNUSED, void *data) const struct config_context *ctx, void *data)
{ {
const char *key_to_match = data; const char *key_to_match = data;
if (!strcmp(key_to_match, var)) { if (!strcmp(key_to_match, var)) {
int parsed = git_config_int(value, value); int parsed = git_config_int(value, value, ctx->kvi);
printf("%d\n", parsed); printf("%d\n", parsed);
} }
return 0; return 0;
@@ -182,7 +182,7 @@ int cmd__config(int argc, const char **argv)
goto exit2; goto exit2;
} }
} }
if (!git_configset_get_value(&cs, argv[2], &v)) { if (!git_configset_get_value(&cs, argv[2], &v, NULL)) {
if (!v) if (!v)
printf("(NULL)\n"); printf("(NULL)\n");
else else

View File

@@ -1275,7 +1275,8 @@ static int find_symref(const char *refname,
} }
static int parse_object_filter_config(const char *var, const char *value, static int parse_object_filter_config(const char *var, const char *value,
struct upload_pack_data *data) const struct key_value_info *kvi,
struct upload_pack_data *data)
{ {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
const char *sub, *key; const char *sub, *key;
@@ -1302,7 +1303,8 @@ static int parse_object_filter_config(const char *var, const char *value,
} }
string_list_insert(&data->allowed_filters, buf.buf)->util = string_list_insert(&data->allowed_filters, buf.buf)->util =
(void *)(intptr_t)1; (void *)(intptr_t)1;
data->tree_filter_max_depth = git_config_ulong(var, value); data->tree_filter_max_depth = git_config_ulong(var, value,
kvi);
} }
strbuf_release(&buf); strbuf_release(&buf);
@@ -1310,7 +1312,7 @@ static int parse_object_filter_config(const char *var, const char *value,
} }
static int upload_pack_config(const char *var, const char *value, static int upload_pack_config(const char *var, const char *value,
const struct config_context *ctx UNUSED, const struct config_context *ctx,
void *cb_data) void *cb_data)
{ {
struct upload_pack_data *data = cb_data; struct upload_pack_data *data = cb_data;
@@ -1331,7 +1333,7 @@ static int upload_pack_config(const char *var, const char *value,
else else
data->allow_uor &= ~ALLOW_ANY_SHA1; data->allow_uor &= ~ALLOW_ANY_SHA1;
} else if (!strcmp("uploadpack.keepalive", var)) { } else if (!strcmp("uploadpack.keepalive", var)) {
data->keepalive = git_config_int(var, value); data->keepalive = git_config_int(var, value, ctx->kvi);
if (!data->keepalive) if (!data->keepalive)
data->keepalive = -1; data->keepalive = -1;
} else if (!strcmp("uploadpack.allowfilter", var)) { } else if (!strcmp("uploadpack.allowfilter", var)) {
@@ -1346,7 +1348,7 @@ static int upload_pack_config(const char *var, const char *value,
data->advertise_sid = git_config_bool(var, value); data->advertise_sid = git_config_bool(var, value);
} }
if (parse_object_filter_config(var, value, data) < 0) if (parse_object_filter_config(var, value, ctx->kvi, data) < 0)
return -1; return -1;
return parse_hide_refs_config(var, value, "uploadpack", &data->hidden_refs); return parse_hide_refs_config(var, value, "uploadpack", &data->hidden_refs);

View File

@@ -835,7 +835,7 @@ int init_worktree_config(struct repository *r)
* Relocate that value to avoid breaking all worktrees with this * Relocate that value to avoid breaking all worktrees with this
* upgrade to worktree config. * 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, if ((res = move_config_setting("core.worktree", core_worktree,
common_config_file, common_config_file,
main_worktree_file))) main_worktree_file)))