X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=config.c;h=2bdff4457be7d5b1e1fd5f6acb558ac41b946a8c;hb=e1dd499513a363434d1ed4cd5e409fea17a93b28;hp=2b79fe76adf791813faf980af340886aefcf38aa;hpb=47f0f94bc796037c43000a9852cdf9209a3c3274;p=thirdparty%2Fgit.git diff --git a/config.c b/config.c index 2b79fe76ad..2bdff4457b 100644 --- a/config.c +++ b/config.c @@ -2006,18 +2006,27 @@ const struct string_list *git_configset_get_value_multi(struct config_set *cs, c return e ? &e->value_list : NULL; } -int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest) +int git_configset_get_string(struct config_set *cs, const char *key, char **dest) { const char *value; if (!git_configset_get_value(cs, key, &value)) - return git_config_string(dest, key, value); + return git_config_string((const char **)dest, key, value); else return 1; } -int git_configset_get_string(struct config_set *cs, const char *key, char **dest) +int git_configset_get_string_tmp(struct config_set *cs, const char *key, + const char **dest) { - return git_configset_get_string_const(cs, key, (const char **)dest); + const char *value; + if (!git_configset_get_value(cs, key, &value)) { + if (!value) + return config_error_nonbool(key); + *dest = value; + return 0; + } else { + return 1; + } } int git_configset_get_int(struct config_set *cs, const char *key, int *dest) @@ -2147,22 +2156,26 @@ const struct string_list *repo_config_get_value_multi(struct repository *repo, return git_configset_get_value_multi(repo->config, key); } -int repo_config_get_string_const(struct repository *repo, - const char *key, const char **dest) +int repo_config_get_string(struct repository *repo, + const char *key, char **dest) { int ret; git_config_check_init(repo); - ret = git_configset_get_string_const(repo->config, key, dest); + ret = git_configset_get_string(repo->config, key, dest); if (ret < 0) git_die_config(key, NULL); return ret; } -int repo_config_get_string(struct repository *repo, - const char *key, char **dest) +int repo_config_get_string_tmp(struct repository *repo, + const char *key, const char **dest) { + int ret; git_config_check_init(repo); - return repo_config_get_string_const(repo, key, (const char **)dest); + ret = git_configset_get_string_tmp(repo->config, key, dest); + if (ret < 0) + git_die_config(key, NULL); + return ret; } int repo_config_get_int(struct repository *repo, @@ -2232,14 +2245,14 @@ const struct string_list *git_config_get_value_multi(const char *key) return repo_config_get_value_multi(the_repository, key); } -int git_config_get_string_const(const char *key, const char **dest) +int git_config_get_string(const char *key, char **dest) { - return repo_config_get_string_const(the_repository, key, dest); + return repo_config_get_string(the_repository, key, dest); } -int git_config_get_string(const char *key, char **dest) +int git_config_get_string_tmp(const char *key, const char **dest) { - return repo_config_get_string(the_repository, key, dest); + return repo_config_get_string_tmp(the_repository, key, dest); } int git_config_get_int(const char *key, int *dest) @@ -2274,7 +2287,7 @@ int git_config_get_pathname(const char *key, const char **dest) int git_config_get_expiry(const char *key, const char **output) { - int ret = git_config_get_string_const(key, output); + int ret = git_config_get_string(key, (char **)output); if (ret) return ret; if (strcmp(*output, "now")) { @@ -2287,11 +2300,11 @@ int git_config_get_expiry(const char *key, const char **output) int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestamp_t now) { - char *expiry_string; + const char *expiry_string; intmax_t days; timestamp_t when; - if (git_config_get_string(key, &expiry_string)) + if (git_config_get_string_tmp(key, &expiry_string)) return 1; /* no such thing */ if (git_parse_signed(expiry_string, &days, maximum_signed_value_of_type(int))) {