Skip to content

Commit f1d3d07

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a0d09c5 commit f1d3d07

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

repo-settings.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static void repo_cfg_int(struct repository *r, const char *key, int *dest,
2020

2121
void prepare_repo_settings(struct repository *r)
2222
{
23+
const struct repo_settings defaults = REPO_SETTINGS_INIT;
2324
int experimental;
2425
int value;
2526
const char *strval;
@@ -29,13 +30,11 @@ void prepare_repo_settings(struct repository *r)
2930
if (!r->gitdir)
3031
BUG("Cannot add settings for uninitialized repository");
3132

32-
if (r->settings.initialized++)
33+
if (r->settings.initialized)
3334
return;
3435

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++;
3938

4039
/* Booleans config or default, cascades to other settings */
4140
repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0);

repo-settings.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ struct repo_settings {
5050

5151
int core_multi_pack_index;
5252
};
53+
#define REPO_SETTINGS_INIT { \
54+
.index_version = -1, \
55+
.core_untracked_cache = UNTRACKED_CACHE_KEEP, \
56+
.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \
57+
}
5358

5459
void prepare_repo_settings(struct repository *r);
5560

0 commit comments

Comments
 (0)