git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v1 2/3] config: introduce repo_config_set* functions

From
Glen Choo <chooglen@google.com>
Date
Nov 11, 2021, 17:16 UTC
Message-ID
<20211111171643.13805-3-chooglen@google.com>
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
Previous: Glen ChooNext: Junio C Hamano
Message 3 of 7 in “make create_branch() accept any repository”
  1. 0/3 make create_branch() accept any repositoryGlen Choo, Nov 11, 2021
  2. 1/3 refs/files-backend: remove the_repositoryGlen Choo, Nov 11, 2021
  3. 2/3 config: introduce repo_config_set* functionsGlen Choo, Nov 11, 2021
  4. Junio C HamanoNov 11, 2021
  5. Glen ChooNov 12, 2021
  6. Glen ChooNov 15, 2021
  7. 3/3 branch: remove implicit the_repository from create_branch()Glen Choo, Nov 11, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.