Skip to content

Commit 03dfb92

Browse files
cloobTechgitster
authored andcommitted
environment: move "branch.autoSetupMerge" into struct repo_config_values
The config value `branch.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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d12d861 commit 03dfb92

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ int cmd_branch(int argc,
724724
static struct ref_sorting *sorting;
725725
struct string_list sorting_options = STRING_LIST_INIT_DUP;
726726
struct ref_format format = REF_FORMAT_INIT;
727+
struct repo_config_values *cfg = repo_config_values(the_repository);
727728
int ret;
728729

729730
struct option options[] = {
@@ -795,7 +796,7 @@ int cmd_branch(int argc,
795796
if (!sorting_options.nr)
796797
string_list_append(&sorting_options, "refname");
797798

798-
track = git_branch_track;
799+
track = cfg->branch_track;
799800

800801
head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD",
801802
0, &head_oid, NULL);

builtin/checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,7 @@ static void die_if_switching_to_a_branch_in_use(struct checkout_opts *opts,
15881588
static int checkout_branch(struct checkout_opts *opts,
15891589
struct branch_info *new_branch_info)
15901590
{
1591+
struct repo_config_values *cfg = repo_config_values(the_repository);
15911592
int noop_switch = (!new_branch_info->name &&
15921593
!opts->new_branch &&
15931594
!opts->force_detach);
@@ -1631,7 +1632,7 @@ static int checkout_branch(struct checkout_opts *opts,
16311632
if (opts->track != BRANCH_TRACK_UNSPECIFIED)
16321633
die(_("'%s' cannot be used with '%s'"), "--detach", "-t");
16331634
} else if (opts->track == BRANCH_TRACK_UNSPECIFIED)
1634-
opts->track = git_branch_track;
1635+
opts->track = cfg->branch_track;
16351636

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

builtin/push.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ static NORETURN void die_push_simple(struct branch *branch,
151151
const char *advice_pushdefault_maybe = "";
152152
const char *advice_automergesimple_maybe = "";
153153
const char *short_upstream = branch->merge[0]->src;
154+
struct repo_config_values *cfg = repo_config_values(the_repository);
154155

155156
skip_prefix(short_upstream, "refs/heads/", &short_upstream);
156157

@@ -162,7 +163,7 @@ static NORETURN void die_push_simple(struct branch *branch,
162163
advice_pushdefault_maybe = _("\n"
163164
"To choose either option permanently, "
164165
"see push.default in 'git help config'.\n");
165-
if (git_branch_track != BRANCH_TRACK_SIMPLE)
166+
if (cfg->branch_track != BRANCH_TRACK_SIMPLE)
166167
advice_automergesimple_maybe = _("\n"
167168
"To avoid automatically configuring "
168169
"an upstream branch when its name\n"

builtin/submodule--helper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3126,9 +3126,10 @@ static int module_create_branch(int argc, const char **argv, const char *prefix,
31263126
N_("git submodule--helper create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>"),
31273127
NULL
31283128
};
3129+
struct repo_config_values *cfg = repo_config_values(the_repository);
31293130

31303131
repo_config(the_repository, git_default_config, NULL);
3131-
track = git_branch_track;
3132+
track = cfg->branch_track;
31323133
argc = parse_options(argc, argv, prefix, options, usage, 0);
31333134

31343135
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 = repo_config_values(the_repository);
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"
@@ -89,6 +90,9 @@ struct repo_config_values {
8990
/* section "core" config values */
9091
char *attributes_file;
9192
int apply_sparse_checkout;
93+
94+
/* section "branch" config values */
95+
enum branch_track branch_track;
9296
};
9397

9498
struct repo_config_values *repo_config_values(struct repository *repo);

0 commit comments

Comments
 (0)