Re: [Outreachy PATCH v5 3/3] environment: move "branch.autoSetupMerge" into `struct repo_config_values`
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 29, 2026, 18:37 UTC
- Message-ID
- <xmqqms1wb6zg.fsf@gitster.g>
- In-Reply-To
- <e7f37bac87aac74ca13f85ae7e393a38d2079b9c.1769256839.git.belkid98@gmail.com>
Olamide Caleb Bello <belkid98@gmail.com> writes:
> -enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
Unlike the other two, this global variable was not zero-initialized, so we can do something like this to initialize it statically in the new world order. That way, we do not need to worry about the repo_config_values_init() helper function, which (1) we can easily forget to adjust, and (2) third-party may not be able to call.
diff --git i/repository.c w/repository.c index d308cd78bf..b540e2ba01 100644 --- i/repository.c +++ w/repository.c @@ -25,7 +25,11 @@ extern struct repository *the_repository; /* The main repository */ -static struct repository the_repo; +static struct repository the_repo = { + .config_values = { + .branch_track = BRANCH_TRACK_REMOTE, + }, +}; struct repository *the_repository = &the_repo; /* > enum rebase_setup_type autorebase = AUTOREBASE_NEVER; > enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED; > #ifndef OBJECT_CREATION_MODE > @@ -607,18 +606,20 @@ static int git_default_i18n_config(const char *var, const char *value) > > static int git_default_branch_config(const char *var, const char *value) > { > + struct repo_config_values *cfg = &the_repository->config_values; > + > if (!strcmp(var, "branch.autosetupmerge")) { > if (value && !strcmp(value, "always")) { > - git_branch_track = BRANCH_TRACK_ALWAYS; > + cfg->branch_track = BRANCH_TRACK_ALWAYS; > return 0; > } else if (value && !strcmp(value, "inherit")) { > - git_branch_track = BRANCH_TRACK_INHERIT; > + cfg->branch_track = BRANCH_TRACK_INHERIT; > return 0; > } else if (value && !strcmp(value, "simple")) { > - git_branch_track = BRANCH_TRACK_SIMPLE; > + cfg->branch_track = BRANCH_TRACK_SIMPLE; > return 0; > } > - git_branch_track = git_config_bool(var, value); > + cfg->branch_track = git_config_bool(var, value); > return 0; > } > if (!strcmp(var, "branch.autosetuprebase")) { > @@ -761,4 +762,5 @@ void repo_config_values_init(struct repo_config_values *cfg) > { > cfg->attributes_file = NULL; > cfg->apply_sparse_checkout = 0; > + cfg->branch_track = BRANCH_TRACK_REMOTE; > } > diff --git a/environment.h b/environment.h > index ddce69c6ba..27161d56ab 100644 > --- a/environment.h > +++ b/environment.h > @@ -2,6 +2,7 @@ > #define ENVIRONMENT_H > > #include "repo-settings.h" > +#include "branch.h" > > /* Double-check local_repo_env below if you add to this list. */ > #define GIT_DIR_ENVIRONMENT "GIT_DIR" > @@ -88,6 +89,9 @@ struct repo_config_values { > /* section "core" config values */ > char *attributes_file; > int apply_sparse_checkout; > + > + /* section "branch" config values */ > + enum branch_track branch_track; > }; > > /*