environment: move autorebase into repo_config_values

The global variable 'autorebase' dictates whether a newly created branch should be configured to automatically rebase by default. Move it into 'struct repo_config_values' to continue the libification effort. The 'enum rebase_setup_type' definition is moved higher up in 'environment.h' so that it is visible to the repository-specific structure. The default state AUTOREBASE_NEVER is now correctly initialized in 'repo_config_values_init()'. Configuration parsing in 'git_default_branch_config()' is updated to write directly to the repository's configuration instance. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com> Mentored-by: Olamide Caleb Bello <belkid98@gmail.com> Signed-off-by: Tian Yuchen <cat@malon.dev> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tian Yuchen committed Jul 14, 2026 at 11:25 UTC 1840ca005fbabc651f9018d88f0f9d8adb91b015
3 files changed +14 -14
branch.c
+1 -1
@@ -61,7 +61,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
61
62 static int should_setup_rebase(const char *origin)
63 {
64 - switch (autorebase) {
64 + switch (repo_config_values(the_repository)->autorebase) {
65 case AUTOREBASE_NEVER:
66 return 0;
67 case AUTOREBASE_LOCAL:
environment.c
+5 -5
@@ -57,7 +57,6 @@ enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
57 enum eol core_eol = EOL_UNSET;
58 int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
59 char *check_roundtrip_encoding;
60 -enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
60 #ifndef OBJECT_CREATION_MODE
61 #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
62 #endif
@@ -601,13 +600,13 @@ static int git_default_branch_config(const char *var, const char *value)
600 if (!value)
601 return config_error_nonbool(var);
602 else if (!strcmp(value, "never"))
604 - autorebase = AUTOREBASE_NEVER;
603 + cfg->autorebase = AUTOREBASE_NEVER;
604 else if (!strcmp(value, "local"))
606 - autorebase = AUTOREBASE_LOCAL;
605 + cfg->autorebase = AUTOREBASE_LOCAL;
606 else if (!strcmp(value, "remote"))
608 - autorebase = AUTOREBASE_REMOTE;
607 + cfg->autorebase = AUTOREBASE_REMOTE;
608 else if (!strcmp(value, "always"))
610 - autorebase = AUTOREBASE_ALWAYS;
609 + cfg->autorebase = AUTOREBASE_ALWAYS;
610 else
611 return error(_("malformed value for %s"), var);
612 return 0;
@@ -728,6 +727,7 @@ void repo_config_values_init(struct repo_config_values *cfg)
727 cfg->apply_default_whitespace = NULL;
728 cfg->apply_default_ignorewhitespace = NULL;
729 cfg->push_default = PUSH_DEFAULT_UNSPECIFIED;
730 + cfg->autorebase = AUTOREBASE_NEVER;
731 cfg->apply_sparse_checkout = 0;
732 cfg->branch_track = BRANCH_TRACK_REMOTE;
733 cfg->trust_ctime = 1;
environment.h
+8 -8
@@ -102,6 +102,13 @@ enum push_default_type {
102 PUSH_DEFAULT_UNSPECIFIED
103 };
104
105 +enum rebase_setup_type {
106 + AUTOREBASE_NEVER = 0,
107 + AUTOREBASE_LOCAL,
108 + AUTOREBASE_REMOTE,
109 + AUTOREBASE_ALWAYS
110 +};
111 +
112 struct repo_config_values {
113 /* section "core" config values */
114 char *attributes_file;
@@ -112,6 +119,7 @@ struct repo_config_values {
119 char *apply_default_whitespace;
120 char *apply_default_ignorewhitespace;
121 enum push_default_type push_default;
122 + enum rebase_setup_type autorebase;
123 int apply_sparse_checkout;
124 int trust_ctime;
125 int check_stat;
@@ -205,14 +213,6 @@ extern unsigned long pack_size_limit_cfg;
213 extern int protect_hfs;
214 extern int protect_ntfs;
215
208 -enum rebase_setup_type {
209 - AUTOREBASE_NEVER = 0,
210 - AUTOREBASE_LOCAL,
211 - AUTOREBASE_REMOTE,
212 - AUTOREBASE_ALWAYS
213 -};
214 -extern enum rebase_setup_type autorebase;
215 -
216 enum object_creation_mode {
217 OBJECT_CREATION_USES_HARDLINKS = 0,
218 OBJECT_CREATION_USES_RENAMES = 1