We have git_config_set() that sets a config value for the_repository's config file, and repo_config_get* that reads config values from a struct repository. Thus, it seems reasonable to have to have repo_git_config_set() that can set values for a config file of a struct repository. Implement repo_config_set() and repo_config_set_gently(), which take struct repository. However, unlike other instances where struct repository is added to a repo_* function, this patch does not change the implementations of git_config_set() or git_config_set_gently(); those functions use the_repository much deeper in their call chain through git_pathdup(). Mark this inconsistency as NEEDSWORK. Signed-off-by: Glen Choo <chooglen@xxxxxxxxxx> --- config.c | 24 ++++++++++++++++++++++++ config.h | 11 +++++++++++ 2 files changed, 35 insertions(+) diff --git a/config.c b/config.c index cd51efe99a..8dd00b8a13 100644 --- a/config.c +++ b/config.c @@ -2869,6 +2869,30 @@ void git_config_set_in_file(const char *config_filename, git_config_set_multivar_in_file(config_filename, key, value, NULL, 0); } +/* + * Sets a config value in a repository. + */ +int repo_config_set_gently(struct repository *r, const char *key, + const char *value) +{ + int ret; + char *path; + + path = repo_git_path(r, "config"); + ret = git_config_set_in_file_gently(path, key, value); + free(path); + return ret; +} + +void repo_config_set(struct repository *r, const char *key, const char *value) +{ + char *path; + + path = repo_git_path(r, "config"); + git_config_set_in_file(path, key, value); + free(path); +} + int git_config_set_gently(const char *key, const char *value) { return git_config_set_multivar_gently(key, value, NULL, 0); diff --git a/config.h b/config.h index 69d733824a..4a6919b984 100644 --- a/config.h +++ b/config.h @@ -253,6 +253,17 @@ void git_config_set_in_file(const char *, const char *, const char *); int git_config_set_gently(const char *, const char *); +/* + * Write config values to a repo's config file. + * + * NEEDSWORK: These are non-the_repository equivalents of + * git_config_set*, but have a completely separate implementation. In + * the ideal case, we git_config_set* should just use the repo_* + * equivalents, just like most other repo_* functions. + */ +int repo_config_set_gently(struct repository *, const char *, const char *); +void repo_config_set(struct repository *, const char *, const char *); + /** * write config values to `.git/config`, takes a key/value pair as parameter. */ -- 2.33.GIT