diff mbox series

[v3,15/21] repo-settings: track defaults close to `struct repo_settings`

Message ID 7a74c8d8a8d640c2f0784984da93813c34fe3982.1726139990.git.ps@pks.im (mailing list archive)
State Accepted
Commit f1d3d07900e42d19f10be55bc2f793034e7d4198
Headers show
Series environment: guard reliance on `the_repository` | expand

Commit Message

Patrick Steinhardt Sept. 12, 2024, 11:30 a.m. UTC
The default values for `struct repo_settings` are set up in
`prepare_repo_settings()`. This is somewhat different from how we
typically do this, namely by providing an `INIT` macro that sets up the
default values for us.

Refactor the code to do the same.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 repo-settings.c | 9 ++++-----
 repo-settings.h | 5 +++++
 2 files changed, 9 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/repo-settings.c b/repo-settings.c
index 6165546e80a..3a76ba276c9 100644
--- a/repo-settings.c
+++ b/repo-settings.c
@@ -20,6 +20,7 @@  static void repo_cfg_int(struct repository *r, const char *key, int *dest,
 
 void prepare_repo_settings(struct repository *r)
 {
+	const struct repo_settings defaults = REPO_SETTINGS_INIT;
 	int experimental;
 	int value;
 	const char *strval;
@@ -29,13 +30,11 @@  void prepare_repo_settings(struct repository *r)
 	if (!r->gitdir)
 		BUG("Cannot add settings for uninitialized repository");
 
-	if (r->settings.initialized++)
+	if (r->settings.initialized)
 		return;
 
-	/* Defaults */
-	r->settings.index_version = -1;
-	r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
-	r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
+	memcpy(&r->settings, &defaults, sizeof(defaults));
+	r->settings.initialized++;
 
 	/* Booleans config or default, cascades to other settings */
 	repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0);
diff --git a/repo-settings.h b/repo-settings.h
index ff20a965373..28f95695b3a 100644
--- a/repo-settings.h
+++ b/repo-settings.h
@@ -50,6 +50,11 @@  struct repo_settings {
 
 	int core_multi_pack_index;
 };
+#define REPO_SETTINGS_INIT { \
+	.index_version = -1, \
+	.core_untracked_cache = UNTRACKED_CACHE_KEEP, \
+	.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \
+}
 
 void prepare_repo_settings(struct repository *r);