Skip to content

Commit 00ea0d3

Browse files
committed
environment: move "branch.autoSetupMerge" into repo-settings
The `branch.autoSetupMerge` repo config is used to detect the tracking mode for the branch against its upstream for a repository. This setting is stored in the global variable `git_branch_track`. Move the setting into the `struct repo-settings` to reduce global dependency to align with the goal of libyfing Git. This change requires us to move the enum to "repo-settings.h", or otherwise we get compilation errors due to include cycles. Mentored-by: Christain Couder <christian.couder@gmail.com> Mentored-by: Usman Akinyemi <usmanakinyemi202@gmail.com> Signed-off-by: Olamide Caleb Bello <belkid98@gmail.com>
1 parent 66ce5f8 commit 00ea0d3

File tree

8 files changed

+36
-31
lines changed

8 files changed

+36
-31
lines changed

branch.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
#ifndef BRANCH_H
22
#define BRANCH_H
33

4+
#include "repo-settings.h"
5+
46
struct repository;
57
struct strbuf;
68

7-
enum branch_track {
8-
BRANCH_TRACK_UNSPECIFIED = -1,
9-
BRANCH_TRACK_NEVER = 0,
10-
BRANCH_TRACK_REMOTE,
11-
BRANCH_TRACK_ALWAYS,
12-
BRANCH_TRACK_EXPLICIT,
13-
BRANCH_TRACK_OVERRIDE,
14-
BRANCH_TRACK_INHERIT,
15-
BRANCH_TRACK_SIMPLE,
16-
};
17-
18-
extern enum branch_track git_branch_track;
199

2010
/* Functions for acting on the information about branches. */
2111

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 = repo_settings_get_branch_track(the_repository);
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 = repo_settings_get_branch_track(the_repository);
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 (repo_settings_get_branch_track(the_repository) != 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 = repo_settings_get_branch_track(the_repository);
31323132
argc = parse_options(argc, argv, prefix, options, usage, 0);
31333133

31343134
if (argc != 3)

environment.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -607,20 +607,6 @@ static int git_default_i18n_config(const char *var, const char *value)
607607

608608
static int git_default_branch_config(const char *var, const char *value)
609609
{
610-
if (!strcmp(var, "branch.autosetupmerge")) {
611-
if (value && !strcmp(value, "always")) {
612-
git_branch_track = BRANCH_TRACK_ALWAYS;
613-
return 0;
614-
} else if (value && !strcmp(value, "inherit")) {
615-
git_branch_track = BRANCH_TRACK_INHERIT;
616-
return 0;
617-
} else if (value && !strcmp(value, "simple")) {
618-
git_branch_track = BRANCH_TRACK_SIMPLE;
619-
return 0;
620-
}
621-
git_branch_track = git_config_bool(var, value);
622-
return 0;
623-
}
624610
if (!strcmp(var, "branch.autosetuprebase")) {
625611
if (!value)
626612
return config_error_nonbool(var);

repo-settings.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,18 @@ void repo_settings_reset_shared_repository(struct repository *repo)
230230
{
231231
repo->settings.shared_repository_initialized = 0;
232232
}
233+
enum branch_track repo_settings_get_branch_track(struct repository *repo)
234+
{
235+
const char *value;
236+
if (!repo_config_get_string_tmp(repo, "branch.autosetupmerge", &value)) {
237+
if (value && !strcmp(value, "always"))
238+
return BRANCH_TRACK_ALWAYS;
239+
else if (value && !strcmp(value, "inherit"))
240+
return BRANCH_TRACK_INHERIT;
241+
else if (value && !strcmp(value, "simple"))
242+
return BRANCH_TRACK_SIMPLE;
243+
else
244+
return git_config_bool("branch.autosetupmerge", value);
245+
}
246+
return BRANCH_TRACK_UNSPECIFIED;
247+
}

repo-settings.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ enum log_refs_config {
2323
LOG_REFS_ALWAYS
2424
};
2525

26+
enum branch_track {
27+
BRANCH_TRACK_UNSPECIFIED = -1,
28+
BRANCH_TRACK_NEVER = 0,
29+
BRANCH_TRACK_REMOTE,
30+
BRANCH_TRACK_ALWAYS,
31+
BRANCH_TRACK_EXPLICIT,
32+
BRANCH_TRACK_OVERRIDE,
33+
BRANCH_TRACK_INHERIT,
34+
BRANCH_TRACK_SIMPLE,
35+
};
36+
2637
struct repo_settings {
2738
int initialized;
2839

@@ -58,7 +69,7 @@ struct repo_settings {
5869
int pack_use_sparse;
5970
int pack_use_path_walk;
6071
enum fetch_negotiation_setting fetch_negotiation_algorithm;
61-
72+
enum branch_track git_branch_track;
6273
int core_multi_pack_index;
6374
int warn_ambiguous_refs; /* lazily loaded via accessor */
6475

@@ -99,4 +110,7 @@ int repo_settings_get_shared_repository(struct repository *repo);
99110
void repo_settings_set_shared_repository(struct repository *repo, int value);
100111
void repo_settings_reset_shared_repository(struct repository *repo);
101112

113+
/*Read the value for "branch.autosetupmerge"*/
114+
enum branch_track repo_settings_get_branch_track(struct repository *repo);
115+
102116
#endif /* REPO_SETTINGS_H */

0 commit comments

Comments
 (0)