This allows branch-specific variables to be tracked locally in `branch.c` instead of globally in `environment.c`. Signed-off-by: Ben Boeckel <mathstuf@xxxxxxxxx> --- branch.c | 32 ++++++++++++++++++++++++++++++++ branch.h | 5 +++++ cache.h | 1 - config.c | 30 ------------------------------ environment.c | 1 - 5 files changed, 37 insertions(+), 32 deletions(-) diff --git a/branch.c b/branch.c index 7a88a4861e..1ef52db89d 100644 --- a/branch.c +++ b/branch.c @@ -9,6 +9,38 @@ #include "commit.h" #include "worktree.h" +static enum rebase_setup_type autorebase = AUTOREBASE_NEVER; + +int git_default_branch_config(const char *var, const char *value) +{ + if (!strcmp(var, "branch.autosetupmerge")) { + if (value && !strcasecmp(value, "always")) { + git_branch_track = BRANCH_TRACK_ALWAYS; + return 0; + } + git_branch_track = git_config_bool(var, value); + return 0; + } + if (!strcmp(var, "branch.autosetuprebase")) { + if (!value) + return config_error_nonbool(var); + else if (!strcmp(value, "never")) + autorebase = AUTOREBASE_NEVER; + else if (!strcmp(value, "local")) + autorebase = AUTOREBASE_LOCAL; + else if (!strcmp(value, "remote")) + autorebase = AUTOREBASE_REMOTE; + else if (!strcmp(value, "always")) + autorebase = AUTOREBASE_ALWAYS; + else + return error(_("malformed value for %s"), var); + return 0; + } + + /* Add other config variables here and to Documentation/config.txt. */ + return 0; +} + struct tracking { struct refspec_item spec; char *src; diff --git a/branch.h b/branch.h index df0be61506..801ff25f92 100644 --- a/branch.h +++ b/branch.h @@ -17,6 +17,11 @@ extern enum branch_track git_branch_track; /* Functions for acting on the information about branches. */ +/* + * Parses branch-related configuration options. + */ +int git_default_branch_config(const char *var, const char *value); + /* * Creates a new branch, where: * diff --git a/cache.h b/cache.h index ba04ff8bd3..6ea1ea5854 100644 --- a/cache.h +++ b/cache.h @@ -1030,7 +1030,6 @@ enum push_default_type { PUSH_DEFAULT_UNSPECIFIED }; -extern enum rebase_setup_type autorebase; extern enum push_default_type push_default; enum object_creation_mode { diff --git a/config.c b/config.c index f33abeab85..840be51710 100644 --- a/config.c +++ b/config.c @@ -1574,36 +1574,6 @@ static int git_default_i18n_config(const char *var, const char *value) return 0; } -static int git_default_branch_config(const char *var, const char *value) -{ - if (!strcmp(var, "branch.autosetupmerge")) { - if (value && !strcasecmp(value, "always")) { - git_branch_track = BRANCH_TRACK_ALWAYS; - return 0; - } - git_branch_track = git_config_bool(var, value); - return 0; - } - if (!strcmp(var, "branch.autosetuprebase")) { - if (!value) - return config_error_nonbool(var); - else if (!strcmp(value, "never")) - autorebase = AUTOREBASE_NEVER; - else if (!strcmp(value, "local")) - autorebase = AUTOREBASE_LOCAL; - else if (!strcmp(value, "remote")) - autorebase = AUTOREBASE_REMOTE; - else if (!strcmp(value, "always")) - autorebase = AUTOREBASE_ALWAYS; - else - return error(_("malformed value for %s"), var); - return 0; - } - - /* Add other config variables here and to Documentation/config.txt. */ - return 0; -} - static int git_default_push_config(const char *var, const char *value) { if (!strcmp(var, "push.default")) { diff --git a/environment.c b/environment.c index 2f27008424..5d45152731 100644 --- a/environment.c +++ b/environment.c @@ -60,7 +60,6 @@ int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN; char *check_roundtrip_encoding = "SHIFT-JIS"; unsigned whitespace_rule_cfg = WS_DEFAULT_RULE; enum branch_track git_branch_track = BRANCH_TRACK_REMOTE; -enum rebase_setup_type autorebase = AUTOREBASE_NEVER; enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED; #ifndef OBJECT_CREATION_MODE #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS -- 2.31.1