From 8868b1ebfb8274a3ef90e1ba69ed45be94f6c3fb Mon Sep 17 00:00:00 2001 From: Glen Choo Date: Wed, 28 Jun 2023 19:26:27 +0000 Subject: 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_() can pass it to git_config_(). 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_() 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_() 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 Signed-off-by: Junio C Hamano --- config.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'config.h') diff --git a/config.h b/config.h index 82eeba94e7..bd366ddb5e 100644 --- a/config.h +++ b/config.h @@ -249,22 +249,26 @@ int git_parse_maybe_bool(const char *); * Parse the string to an integer, including unit factors. Dies on error; * 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. */ -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 * 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 @@ -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 * 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_int(struct config_set *cs, const char *key, int *dest); -- cgit v1.2.3