git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Subject: [PATCH 08/20] config: introduce missing setters that take repo as parameter
Date: Wed, 7 Aug 2024 08:57:19 +0200	[thread overview]
Message-ID: <feae2ad31ac91baae75c46c22c5c3ef3b58c1897.1723013714.git.ps@pks.im> (raw)
In-Reply-To: <cover.1723013714.git.ps@pks.im>

[-- Attachment #1: Type: text/plain, Size: 9670 bytes --]

While we already provide some of the config-setting interfaces with a
`struct repository` as parameter, others only have a variant that
implicitly depend on `the_repository`. Fill in those gaps such that we
can start to deprecate the repo-less variants.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 config.c | 93 ++++++++++++++++++++++++++++++++++++++++++++------------
 config.h | 15 ++++++++-
 2 files changed, 87 insertions(+), 21 deletions(-)

diff --git a/config.c b/config.c
index 6421894614..ac89b708e7 100644
--- a/config.c
+++ b/config.c
@@ -3178,21 +3178,39 @@ static void maybe_remove_section(struct config_store_data *store,
 		*end_offset = store->parsed[store->parsed_nr - 1].end;
 }
 
+int repo_config_set_in_file_gently(struct repository *r, const char *config_filename,
+				   const char *key, const char *comment, const char *value)
+{
+	return repo_config_set_multivar_in_file_gently(r, config_filename, key, value, NULL, comment, 0);
+}
+
 int git_config_set_in_file_gently(const char *config_filename,
 				  const char *key, const char *comment, const char *value)
 {
-	return git_config_set_multivar_in_file_gently(config_filename, key, value, NULL, comment, 0);
+	return repo_config_set_in_file_gently(the_repository, config_filename,
+					      key, comment, value);
+}
+
+void repo_config_set_in_file(struct repository *r, const char *config_filename,
+			     const char *key, const char *value)
+{
+	repo_config_set_multivar_in_file(r, config_filename, key, value, NULL, 0);
 }
 
 void git_config_set_in_file(const char *config_filename,
 			    const char *key, const char *value)
 {
-	git_config_set_multivar_in_file(config_filename, key, value, NULL, 0);
+	repo_config_set_in_file(the_repository, config_filename, key, value);
+}
+
+int repo_config_set_gently(struct repository *r, const char *key, const char *value)
+{
+	return repo_config_set_multivar_gently(r, key, value, NULL, 0);
 }
 
 int git_config_set_gently(const char *key, const char *value)
 {
-	return git_config_set_multivar_gently(key, value, NULL, 0);
+	return repo_config_set_gently(the_repository, key, value);
 }
 
 int repo_config_set_worktree_gently(struct repository *r,
@@ -3209,13 +3227,18 @@ int repo_config_set_worktree_gently(struct repository *r,
 	return repo_config_set_multivar_gently(r, key, value, NULL, 0);
 }
 
-void git_config_set(const char *key, const char *value)
+void repo_config_set(struct repository *r, const char *key, const char *value)
 {
-	git_config_set_multivar(key, value, NULL, 0);
+	repo_config_set_multivar(r, key, value, NULL, 0);
 
 	trace2_cmd_set_config(key, value);
 }
 
+void git_config_set(const char *key, const char *value)
+{
+	repo_config_set(the_repository, key, value);
+}
+
 char *git_config_prepare_comment_string(const char *comment)
 {
 	size_t leading_blanks;
@@ -3293,11 +3316,12 @@ static void validate_comment_string(const char *comment)
  * - the config file is removed and the lock file rename()d to it.
  *
  */
-int git_config_set_multivar_in_file_gently(const char *config_filename,
-					   const char *key, const char *value,
-					   const char *value_pattern,
-					   const char *comment,
-					   unsigned flags)
+int repo_config_set_multivar_in_file_gently(struct repository *r,
+					    const char *config_filename,
+					    const char *key, const char *value,
+					    const char *value_pattern,
+					    const char *comment,
+					    unsigned flags)
 {
 	int fd = -1, in_fd = -1;
 	int ret;
@@ -3317,7 +3341,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
 	store.multi_replace = (flags & CONFIG_FLAGS_MULTI_REPLACE) != 0;
 
 	if (!config_filename)
-		config_filename = filename_buf = git_pathdup("config");
+		config_filename = filename_buf = repo_git_path(r, "config");
 
 	/*
 	 * The lock serves a purpose in addition to locking: the new
@@ -3526,7 +3550,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
 	ret = 0;
 
 	/* Invalidate the config cache */
-	git_config_clear();
+	repo_config_clear(r);
 
 out_free:
 	rollback_lock_file(&lock);
@@ -3543,12 +3567,24 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
 	goto out_free;
 }
 
-void git_config_set_multivar_in_file(const char *config_filename,
-				     const char *key, const char *value,
-				     const char *value_pattern, unsigned flags)
+int git_config_set_multivar_in_file_gently(const char *config_filename,
+					   const char *key, const char *value,
+					   const char *value_pattern,
+					   const char *comment,
+					   unsigned flags)
 {
-	if (!git_config_set_multivar_in_file_gently(config_filename, key, value,
-						    value_pattern, NULL, flags))
+	return repo_config_set_multivar_in_file_gently(the_repository, config_filename,
+						       key, value, value_pattern,
+						       comment, flags);
+}
+
+void repo_config_set_multivar_in_file(struct repository *r,
+				      const char *config_filename,
+				      const char *key, const char *value,
+				      const char *value_pattern, unsigned flags)
+{
+	if (!repo_config_set_multivar_in_file_gently(r, config_filename, key, value,
+						     value_pattern, NULL, flags))
 		return;
 	if (value)
 		die(_("could not set '%s' to '%s'"), key, value);
@@ -3556,6 +3592,14 @@ void git_config_set_multivar_in_file(const char *config_filename,
 		die(_("could not unset '%s'"), key);
 }
 
+void git_config_set_multivar_in_file(const char *config_filename,
+				     const char *key, const char *value,
+				     const char *value_pattern, unsigned flags)
+{
+	repo_config_set_multivar_in_file(the_repository, config_filename,
+					 key, value, value_pattern, flags);
+}
+
 int git_config_set_multivar_gently(const char *key, const char *value,
 				   const char *value_pattern, unsigned flags)
 {
@@ -3576,12 +3620,21 @@ int repo_config_set_multivar_gently(struct repository *r, const char *key,
 	return res;
 }
 
+void repo_config_set_multivar(struct repository *r,
+			      const char *key, const char *value,
+			      const char *value_pattern, unsigned flags)
+{
+	char *file = repo_git_path(r, "config");
+	git_config_set_multivar_in_file(file, key, value,
+					value_pattern, flags);
+	free(file);
+}
+
 void git_config_set_multivar(const char *key, const char *value,
 			     const char *value_pattern, unsigned flags)
 {
-	git_config_set_multivar_in_file(git_path("config"),
-					key, value, value_pattern,
-					flags);
+	repo_config_set_multivar(the_repository, key, value,
+				 value_pattern, flags);
 }
 
 static size_t section_name_match (const char *buf, const char *name)
diff --git a/config.h b/config.h
index 54b47dec9e..b13e1bfb8d 100644
--- a/config.h
+++ b/config.h
@@ -298,14 +298,18 @@ int git_config_pathname(char **, const char *, const char *);
 int git_config_expiry_date(timestamp_t *, const char *, const char *);
 int git_config_color(char *, const char *, const char *);
 int git_config_set_in_file_gently(const char *, const char *, const char *, const char *);
+int repo_config_set_in_file_gently(struct repository *r, const char *config_filename,
+				   const char *key, const char *comment, const char *value);
 
 /**
  * write config values to a specific config file, takes a key/value pair as
  * parameter.
  */
 void git_config_set_in_file(const char *, const char *, const char *);
+void repo_config_set_in_file(struct repository *, const char *, const char *, const char *);
 
 int git_config_set_gently(const char *, const char *);
+int repo_config_set_gently(struct repository *r, const char *, const char *);
 
 /**
  * Write a config value that should apply to the current worktree. If
@@ -318,6 +322,7 @@ int repo_config_set_worktree_gently(struct repository *, const char *, const cha
  * write config values to `.git/config`, takes a key/value pair as parameter.
  */
 void git_config_set(const char *, const char *);
+void repo_config_set(struct repository *, const char *, const char *);
 
 int git_config_parse_key(const char *, char **, size_t *);
 
@@ -341,9 +346,11 @@ int git_config_parse_key(const char *, char **, size_t *);
 #define CONFIG_FLAGS_FIXED_VALUE (1 << 1)
 
 int git_config_set_multivar_gently(const char *, const char *, const char *, unsigned);
-void git_config_set_multivar(const char *, const char *, const char *, unsigned);
 int repo_config_set_multivar_gently(struct repository *, const char *, const char *, const char *, unsigned);
+void git_config_set_multivar(const char *, const char *, const char *, unsigned);
+void repo_config_set_multivar(struct repository *r, const char *, const char *, const char *, unsigned);
 int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, const char *, unsigned);
+int repo_config_set_multivar_in_file_gently(struct repository *, const char *, const char *, const char *, const char *, const char *, unsigned);
 
 char *git_config_prepare_comment_string(const char *);
 
@@ -372,6 +379,12 @@ void git_config_set_multivar_in_file(const char *config_filename,
 				     const char *value,
 				     const char *value_pattern,
 				     unsigned flags);
+void repo_config_set_multivar_in_file(struct repository *r,
+				      const char *config_filename,
+				      const char *key,
+				      const char *value,
+				      const char *value_pattern,
+				      unsigned flags);
 
 /**
  * rename or remove sections in the config file
-- 
2.46.0.dirty


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2024-08-07  6:57 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-07  6:56 [PATCH 00/20] Stop using `the_repository` in "config.c" Patrick Steinhardt
2024-08-07  6:56 ` [PATCH 01/20] path: expose `do_git_path()` as `repo_git_pathv()` Patrick Steinhardt
2024-08-09 16:58   ` Justin Tobler
2024-08-13  9:25     ` Patrick Steinhardt
2024-08-07  6:56 ` [PATCH 02/20] path: expose `do_git_common_path()` as `strbuf_git_common_pathv()` Patrick Steinhardt
2024-08-09 17:18   ` Justin Tobler
2024-08-09 17:32     ` Junio C Hamano
2024-08-13  9:25       ` Patrick Steinhardt
2024-08-13 15:12         ` Junio C Hamano
2024-08-07  6:56 ` [PATCH 03/20] editor: do not rely on `the_repository` for interactive edits Patrick Steinhardt
2024-08-09 17:36   ` Justin Tobler
2024-08-07  6:57 ` [PATCH 04/20] hooks: remove implicit dependency on `the_repository` Patrick Steinhardt
2024-08-07  6:57 ` [PATCH 05/20] path: stop relying on `the_repository` when reporting garbage Patrick Steinhardt
2024-08-07  6:57 ` [PATCH 06/20] path: stop relying on `the_repository` in `worktree_git_path()` Patrick Steinhardt
2024-08-09 19:02   ` Justin Tobler
2024-08-13  9:25     ` Patrick Steinhardt
2024-08-07  6:57 ` [PATCH 07/20] path: hide functions using `the_repository` by default Patrick Steinhardt
2024-08-09 19:43   ` Justin Tobler
2024-08-13  9:25     ` Patrick Steinhardt
2024-08-07  6:57 ` Patrick Steinhardt [this message]
2024-08-09 20:07   ` [PATCH 08/20] config: introduce missing setters that take repo as parameter Justin Tobler
2024-08-13  9:25     ` Patrick Steinhardt
2024-08-07  6:57 ` [PATCH 09/20] config: expose `repo_config_clear()` Patrick Steinhardt
2024-08-07  6:57 ` [PATCH 10/20] config: pass repo to `git_config_get_index_threads()` Patrick Steinhardt
2024-08-07  6:57 ` [PATCH 11/20] config: pass repo to `git_config_get_split_index()` Patrick Steinhardt
2024-08-07  6:57 ` [PATCH 12/20] config: pass repo to `git_config_get_max_percent_split_change()` Patrick Steinhardt
2024-08-07  6:57 ` [PATCH 13/20] config: pass repo to `git_config_get_expiry()` Patrick Steinhardt
2024-08-07  6:57 ` [PATCH 14/20] config: pass repo to `git_config_get_expiry_in_days()` Patrick Steinhardt
2024-08-09 20:21   ` Justin Tobler
2024-08-09 21:14     ` Junio C Hamano
2024-08-07  6:57 ` [PATCH 15/20] config: pass repo to `git_die_config()` Patrick Steinhardt
2024-08-07  6:57 ` [PATCH 16/20] config: pass repo to functions that rename or copy sections Patrick Steinhardt
2024-08-07  6:58 ` [PATCH 17/20] config: don't have setters depend on `the_repository` Patrick Steinhardt
2024-08-07  6:58 ` [PATCH 18/20] config: don't depend on `the_repository` with branch conditions Patrick Steinhardt
2024-08-09 20:47   ` Justin Tobler
2024-08-13  9:25     ` Patrick Steinhardt
2024-08-07  6:58 ` [PATCH 19/20] global: prepare for hiding away repo-less config functions Patrick Steinhardt
2024-08-09 20:57   ` Justin Tobler
2024-08-07  6:58 ` [PATCH 20/20] config: hide functions using `the_repository` by default Patrick Steinhardt
2024-08-09 21:13   ` Justin Tobler
2024-08-07  9:48 ` [PATCH 00/20] Stop using `the_repository` in "config.c" Ghanshyam Thakkar
2024-08-07 13:11   ` Patrick Steinhardt
2024-08-13  9:13 ` [PATCH v2 " Patrick Steinhardt
2024-08-13  9:13   ` [PATCH v2 01/20] path: expose `do_git_path()` as `repo_git_pathv()` Patrick Steinhardt
2024-08-13  9:13   ` [PATCH v2 02/20] path: expose `do_git_common_path()` as `repo_common_pathv()` Patrick Steinhardt
2024-08-13  9:13   ` [PATCH v2 03/20] editor: do not rely on `the_repository` for interactive edits Patrick Steinhardt
2024-08-13  9:13   ` [PATCH v2 04/20] hooks: remove implicit dependency on `the_repository` Patrick Steinhardt
2024-08-13  9:13   ` [PATCH v2 05/20] path: stop relying on `the_repository` when reporting garbage Patrick Steinhardt
2024-08-14 18:28     ` Calvin Wan
2024-08-15  5:26       ` Patrick Steinhardt
2024-08-13  9:13   ` [PATCH v2 06/20] path: stop relying on `the_repository` in `worktree_git_path()` Patrick Steinhardt
2024-08-13  9:13   ` [PATCH v2 07/20] path: hide functions using `the_repository` by default Patrick Steinhardt
2024-08-13  9:13   ` [PATCH v2 08/20] config: introduce missing setters that take repo as parameter Patrick Steinhardt
2024-08-13  9:13   ` [PATCH v2 09/20] config: expose `repo_config_clear()` Patrick Steinhardt
2024-08-13  9:13   ` [PATCH v2 10/20] config: pass repo to `git_config_get_index_threads()` Patrick Steinhardt
2024-08-13  9:13   ` [PATCH v2 11/20] config: pass repo to `git_config_get_split_index()` Patrick Steinhardt
2024-08-13  9:13   ` [PATCH v2 12/20] config: pass repo to `git_config_get_max_percent_split_change()` Patrick Steinhardt
2024-08-13  9:13   ` [PATCH v2 13/20] config: pass repo to `git_config_get_expiry()` Patrick Steinhardt
2024-08-13  9:14   ` [PATCH v2 14/20] config: pass repo to `git_config_get_expiry_in_days()` Patrick Steinhardt
2024-08-13  9:14   ` [PATCH v2 15/20] config: pass repo to `git_die_config()` Patrick Steinhardt
2024-08-13  9:14   ` [PATCH v2 16/20] config: pass repo to functions that rename or copy sections Patrick Steinhardt
2024-08-13  9:14   ` [PATCH v2 17/20] config: don't have setters depend on `the_repository` Patrick Steinhardt
2024-08-13  9:14   ` [PATCH v2 18/20] config: don't depend on `the_repository` with branch conditions Patrick Steinhardt
2024-08-13  9:14   ` [PATCH v2 19/20] global: prepare for hiding away repo-less config functions Patrick Steinhardt
2024-08-13  9:14   ` [PATCH v2 20/20] config: hide functions using `the_repository` by default Patrick Steinhardt
2024-08-13 17:07   ` [PATCH v2 00/20] Stop using `the_repository` in "config.c" Junio C Hamano
2024-08-14 19:29   ` Calvin Wan
2024-08-15  5:13     ` Patrick Steinhardt
2024-08-15  0:58   ` Justin Tobler

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=feae2ad31ac91baae75c46c22c5c3ef3b58c1897.1723013714.git.ps@pks.im \
    --to=ps@pks.im \
    --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.
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 NNTP newsgroup(s).