Skip to content

Commit c74973d

Browse files
committed
environment: move "branch.autoSetupMerge" into struct repo_config_values
The config value `brach.autoSetupMerge` is parsed in `git_default_branch_config()` and stored in the global variable `git_branch_track`. This global variable can be overwritten by another repository when multiple Git repos run in the the same process. Move this value into `struct repo_config_values` in the_repository to retain current behaviours and move towards libifying Git. Since the variable is no longer a global variable, it has been renamed to `branch_track` in the struct `repo_config_values`. Suggested-by: Phillip Wood <phillip.wood123@gmail.com> Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Usman Akinyemi <usmanakinyemi202@gmail.com> Signed-off-by: Olamide Caleb Bello <belkid98@gmail.com>
1 parent e44ce7b commit c74973d

File tree

7 files changed

+15
-11
lines changed

7 files changed

+15
-11
lines changed

branch.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ enum branch_track {
1515
BRANCH_TRACK_SIMPLE,
1616
};
1717

18-
extern enum branch_track git_branch_track;
19-
2018
/* Functions for acting on the information about branches. */
2119

2220
/**

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ int cmd_branch(int argc,
795795
if (!sorting_options.nr)
796796
string_list_append(&sorting_options, "refname");
797797

798-
track = git_branch_track;
798+
track = the_repository->config_values.branch_track;
799799

800800
head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD",
801801
0, &head_oid, NULL);

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,7 @@ static int checkout_branch(struct checkout_opts *opts,
16311631
if (opts->track != BRANCH_TRACK_UNSPECIFIED)
16321632
die(_("'%s' cannot be used with '%s'"), "--detach", "-t");
16331633
} else if (opts->track == BRANCH_TRACK_UNSPECIFIED)
1634-
opts->track = git_branch_track;
1634+
opts->track = the_repository->config_values.branch_track;
16351635

16361636
if (new_branch_info->name && !new_branch_info->commit)
16371637
die(_("Cannot switch branch to a non-commit '%s'"),

builtin/push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static NORETURN void die_push_simple(struct branch *branch,
162162
advice_pushdefault_maybe = _("\n"
163163
"To choose either option permanently, "
164164
"see push.default in 'git help config'.\n");
165-
if (git_branch_track != BRANCH_TRACK_SIMPLE)
165+
if (the_repository->config_values.branch_track != BRANCH_TRACK_SIMPLE)
166166
advice_automergesimple_maybe = _("\n"
167167
"To avoid automatically configuring "
168168
"an upstream branch when its name\n"

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3128,7 +3128,7 @@ static int module_create_branch(int argc, const char **argv, const char *prefix,
31283128
};
31293129

31303130
repo_config(the_repository, git_default_config, NULL);
3131-
track = git_branch_track;
3131+
track = the_repository->config_values.branch_track;
31323132
argc = parse_options(argc, argv, prefix, options, usage, 0);
31333133

31343134
if (argc != 3)

environment.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
6666
enum eol core_eol = EOL_UNSET;
6767
int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
6868
char *check_roundtrip_encoding;
69-
enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
7069
enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
7170
enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
7271
#ifndef OBJECT_CREATION_MODE
@@ -607,18 +606,20 @@ static int git_default_i18n_config(const char *var, const char *value)
607606

608607
static int git_default_branch_config(const char *var, const char *value)
609608
{
609+
struct repo_config_values *cfg = &the_repository->config_values;
610+
610611
if (!strcmp(var, "branch.autosetupmerge")) {
611612
if (value && !strcmp(value, "always")) {
612-
git_branch_track = BRANCH_TRACK_ALWAYS;
613+
cfg->branch_track = BRANCH_TRACK_ALWAYS;
613614
return 0;
614615
} else if (value && !strcmp(value, "inherit")) {
615-
git_branch_track = BRANCH_TRACK_INHERIT;
616+
cfg->branch_track = BRANCH_TRACK_INHERIT;
616617
return 0;
617618
} else if (value && !strcmp(value, "simple")) {
618-
git_branch_track = BRANCH_TRACK_SIMPLE;
619+
cfg->branch_track = BRANCH_TRACK_SIMPLE;
619620
return 0;
620621
}
621-
git_branch_track = git_config_bool(var, value);
622+
cfg->branch_track = git_config_bool(var, value);
622623
return 0;
623624
}
624625
if (!strcmp(var, "branch.autosetuprebase")) {
@@ -761,4 +762,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
761762
{
762763
cfg->attributes_file = NULL;
763764
cfg->apply_sparse_checkout = 0;
765+
cfg->branch_track = BRANCH_TRACK_REMOTE;
764766
}

environment.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define ENVIRONMENT_H
33

44
#include "repo-settings.h"
5+
#include "branch.h"
56

67
/* Double-check local_repo_env below if you add to this list. */
78
#define GIT_DIR_ENVIRONMENT "GIT_DIR"
@@ -88,6 +89,9 @@ struct repo_config_values {
8889
/* section "core" config values */
8990
char *attributes_file;
9091
int apply_sparse_checkout;
92+
93+
/* section "branch" config values */
94+
enum branch_track branch_track;
9195
};
9296

9397
/*

0 commit comments

Comments
 (0)