]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repo-settings: track defaults close to `struct repo_settings`
authorPatrick Steinhardt <ps@pks.im>
Thu, 12 Sep 2024 11:30:07 +0000 (13:30 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Sep 2024 17:15:42 +0000 (10:15 -0700)
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>
repo-settings.c
repo-settings.h

index 6165546e80abd56fdde88d266de363f565f367d5..3a76ba276c9a4388840262961de589cb63eb4cb6 100644 (file)
@@ -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);
index ff20a965373ebbbc0a7ee440313b26297a669aa3..28f95695b3a437798396ec4dcb8294ce79737e35 100644 (file)
@@ -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);