From: Glen Choo <chooglen@google.com>
To: git@vger.kernel.org
Cc: Glen Choo <chooglen@google.com>
Subject: [PATCH v1 2/3] config: introduce repo_config_set* functions
Date: Thu, 11 Nov 2021 09:16:42 -0800 [thread overview]
Message-ID: <20211111171643.13805-3-chooglen@google.com> (raw)
In-Reply-To: <20211111171643.13805-1-chooglen@google.com>
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@google.com>
---
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
next prev parent reply other threads:[~2021-11-11 17:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-11 17:16 [PATCH v1 0/3] make create_branch() accept any repository Glen Choo
2021-11-11 17:16 ` [PATCH v1 1/3] refs/files-backend: remove the_repository Glen Choo
2021-11-11 17:16 ` Glen Choo [this message]
2021-11-11 20:24 ` [PATCH v1 2/3] config: introduce repo_config_set* functions Junio C Hamano
2021-11-12 0:45 ` Glen Choo
2021-11-15 22:17 ` Glen Choo
2021-11-11 17:16 ` [PATCH v1 3/3] branch: remove implicit the_repository from create_branch() Glen Choo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211111171643.13805-3-chooglen@google.com \
--to=chooglen@google.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).