environment: move object_creation_mode into repo_config_values

The global variable 'object_creation_mode' controls how Git creates object files, specifically determining whether to use hardlinks or renames when moving temporary files into the object database. Move it into 'struct repo_config_values' to continue the libification effort. Move the 'enum object_creation_mode' definition higher up in 'environment.h' to ensure it is visible to the structure. Initialize the per-repository value to its default macro value OBJECT_CREATION_MODE inside 'repo_config_values_init()'. Update configuration parsing in 'git_default_core_config()' to write directly to the repository-specific configuration structure. 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 b5efc34b10b3484e18e7a55260f0f06e423eba28
3 files changed +11 -10
environment.c
+3 -3
@@ -60,7 +60,6 @@ char *check_roundtrip_encoding;
60 #ifndef OBJECT_CREATION_MODE
61 #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
62 #endif
63 -enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
63 int grafts_keep_true_parents;
64 unsigned long pack_size_limit_cfg;
65
@@ -512,9 +511,9 @@ int git_default_core_config(const char *var, const char *value,
511 if (!value)
512 return config_error_nonbool(var);
513 if (!strcmp(value, "rename"))
515 - object_creation_mode = OBJECT_CREATION_USES_RENAMES;
514 + cfg->object_creation_mode = OBJECT_CREATION_USES_RENAMES;
515 else if (!strcmp(value, "link"))
517 - object_creation_mode = OBJECT_CREATION_USES_HARDLINKS;
516 + cfg->object_creation_mode = OBJECT_CREATION_USES_HARDLINKS;
517 else
518 die(_("invalid mode for object creation: %s"), value);
519 return 0;
@@ -728,6 +727,7 @@ void repo_config_values_init(struct repo_config_values *cfg)
727 cfg->apply_default_ignorewhitespace = NULL;
728 cfg->push_default = PUSH_DEFAULT_UNSPECIFIED;
729 cfg->autorebase = AUTOREBASE_NEVER;
730 + cfg->object_creation_mode = OBJECT_CREATION_MODE;
731 cfg->apply_sparse_checkout = 0;
732 cfg->branch_track = BRANCH_TRACK_REMOTE;
733 cfg->trust_ctime = 1;
environment.h
+6 -6
@@ -109,6 +109,11 @@ enum rebase_setup_type {
109 AUTOREBASE_ALWAYS
110 };
111
112 +enum object_creation_mode {
113 + OBJECT_CREATION_USES_HARDLINKS = 0,
114 + OBJECT_CREATION_USES_RENAMES = 1
115 +};
116 +
117 struct repo_config_values {
118 /* section "core" config values */
119 char *attributes_file;
@@ -120,6 +125,7 @@ struct repo_config_values {
125 char *apply_default_ignorewhitespace;
126 enum push_default_type push_default;
127 enum rebase_setup_type autorebase;
128 + enum object_creation_mode object_creation_mode;
129 int apply_sparse_checkout;
130 int trust_ctime;
131 int check_stat;
@@ -213,12 +219,6 @@ extern unsigned long pack_size_limit_cfg;
219 extern int protect_hfs;
220 extern int protect_ntfs;
221
216 -enum object_creation_mode {
217 - OBJECT_CREATION_USES_HARDLINKS = 0,
218 - OBJECT_CREATION_USES_RENAMES = 1
219 -};
220 -extern enum object_creation_mode object_creation_mode;
221 -
222 extern int grafts_keep_true_parents;
223
224 const char *get_log_output_encoding(void);
object-file.c
+2 -1
@@ -411,11 +411,12 @@ int finalize_object_file_flags(struct repository *repo,
411 {
412 unsigned retries = 0;
413 int ret;
414 + struct repo_config_values *cfg = repo_config_values(repo);
415
416 retry:
417 ret = 0;
418
418 - if (object_creation_mode == OBJECT_CREATION_USES_RENAMES)
419 + if (cfg->object_creation_mode == OBJECT_CREATION_USES_RENAMES)
420 goto try_rename;
421 else if (link(tmpfile, filename))
422 ret = errno;