repo-settings: track defaults close to `struct repo_settings`
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Sep 12, 2024 at 13:30 UTC
f1d3d07900e42d19f10be55bc2f793034e7d4198
2 files changed
+9
-5
repo-settings.c
+4
-5
@@ -20,6 +20,7 @@ static void repo_cfg_int(struct repository *r, const char *key, int *dest,
20
21
void prepare_repo_settings(struct repository *r)
22
{
23
+ const struct repo_settings defaults = REPO_SETTINGS_INIT;
24
int experimental;
25
int value;
26
const char *strval;
@@ -29,13 +30,11 @@ void prepare_repo_settings(struct repository *r)
30
if (!r->gitdir)
31
BUG("Cannot add settings for uninitialized repository");
32
32
- if (r->settings.initialized++)
33
+ if (r->settings.initialized)
34
return;
35
35
- /* Defaults */
36
- r->settings.index_version = -1;
37
- r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
38
- r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
36
+ memcpy(&r->settings, &defaults, sizeof(defaults));
37
+ r->settings.initialized++;
38
39
/* Booleans config or default, cascades to other settings */
40
repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0);
repo-settings.h
+5
@@ -50,6 +50,11 @@ struct repo_settings {
50
51
int core_multi_pack_index;
52
};
53
+#define REPO_SETTINGS_INIT { \
54
+ .index_version = -1, \
55
+ .core_untracked_cache = UNTRACKED_CACHE_KEEP, \
56
+ .fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \
57
+}
58
59
void prepare_repo_settings(struct repository *r);
60