git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Subject: [PATCH 18/19] environment: move object creation mode into repo settings
Date: Wed, 09 Jul 2025 13:17:28 +0200	[thread overview]
Message-ID: <20250709-pks-object-file-wo-the-repository-v1-18-62627b55707f@pks.im> (raw)
In-Reply-To: <20250709-pks-object-file-wo-the-repository-v1-0-62627b55707f@pks.im>

The object creation mode controls whether we use hardlinks or renames to
move objects into place. The value for that config is stored in a global
variable, which is bad practice nowadays.

Refactor the config value so that it is instead tracked via our repo
settings.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 config.c        | 12 ------------
 environment.c   |  4 ----
 environment.h   |  6 ------
 object-file.c   |  3 ++-
 repo-settings.c | 16 ++++++++++++++++
 repo-settings.h |  6 ++++++
 6 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/config.c b/config.c
index b7d1fa90fbf..81a29e37010 100644
--- a/config.c
+++ b/config.c
@@ -1568,18 +1568,6 @@ static int git_default_core_config(const char *var, const char *value,
 		return 0;
 	}
 
-	if (!strcmp(var, "core.createobject")) {
-		if (!value)
-			return config_error_nonbool(var);
-		if (!strcmp(value, "rename"))
-			object_creation_mode = OBJECT_CREATION_USES_RENAMES;
-		else if (!strcmp(value, "link"))
-			object_creation_mode = OBJECT_CREATION_USES_HARDLINKS;
-		else
-			die(_("invalid mode for object creation: %s"), value);
-		return 0;
-	}
-
 	if (!strcmp(var, "core.sparsecheckout")) {
 		core_apply_sparse_checkout = git_config_bool(var, value);
 		return 0;
diff --git a/environment.c b/environment.c
index dbb186b56d0..ed0e9c62346 100644
--- a/environment.c
+++ b/environment.c
@@ -56,10 +56,6 @@ char *check_roundtrip_encoding;
 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
-#endif
-enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
 int grafts_keep_true_parents;
 int core_apply_sparse_checkout;
 int core_sparse_checkout_cone;
diff --git a/environment.h b/environment.h
index 4245b58af6e..7c5ddc1da8f 100644
--- a/environment.h
+++ b/environment.h
@@ -179,12 +179,6 @@ enum push_default_type {
 };
 extern enum push_default_type push_default;
 
-enum object_creation_mode {
-	OBJECT_CREATION_USES_HARDLINKS = 0,
-	OBJECT_CREATION_USES_RENAMES = 1
-};
-extern enum object_creation_mode object_creation_mode;
-
 extern int grafts_keep_true_parents;
 
 extern int repository_format_precious_objects;
diff --git a/object-file.c b/object-file.c
index 0afd39dd346..55396d4eaeb 100644
--- a/object-file.c
+++ b/object-file.c
@@ -600,7 +600,8 @@ int finalize_object_file_flags(struct repository *repo,
 retry:
 	ret = 0;
 
-	if (object_creation_mode == OBJECT_CREATION_USES_RENAMES)
+	prepare_repo_settings(repo);
+	if (repo->settings.object_creation_mode == OBJECT_CREATION_USES_RENAMES)
 		goto try_rename;
 	else if (link(tmpfile, filename))
 		ret = errno;
diff --git a/repo-settings.c b/repo-settings.c
index 1d3626018a0..38a4145c3eb 100644
--- a/repo-settings.c
+++ b/repo-settings.c
@@ -189,6 +189,22 @@ void prepare_repo_settings(struct repository *r)
 		if (!pack_compression_seen)
 			r->settings.pack_compression_level = Z_DEFAULT_COMPRESSION;
 	}
+
+	if (!repo_config_get_string_tmp(r, "core.createobject", &strval)) {
+		if (!strval)
+			die(_("missing value for '%s'"), strval);
+		if (!strcmp(strval, "rename"))
+			r->settings.object_creation_mode = OBJECT_CREATION_USES_RENAMES;
+		else if (!strcmp(strval, "link"))
+			r->settings.object_creation_mode = OBJECT_CREATION_USES_HARDLINKS;
+		else
+			die(_("invalid mode for object creation: %s"), strval);
+	} else {
+#ifndef OBJECT_CREATION_MODE
+# define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
+#endif
+		r->settings.object_creation_mode = OBJECT_CREATION_MODE;
+	}
 }
 
 void repo_settings_clear(struct repository *r)
diff --git a/repo-settings.h b/repo-settings.h
index f60900317cf..18074115145 100644
--- a/repo-settings.h
+++ b/repo-settings.h
@@ -23,6 +23,11 @@ enum log_refs_config {
 	LOG_REFS_ALWAYS
 };
 
+enum object_creation_mode {
+	OBJECT_CREATION_USES_HARDLINKS = 0,
+	OBJECT_CREATION_USES_RENAMES = 1
+};
+
 struct repo_settings {
 	int initialized;
 
@@ -60,6 +65,7 @@ struct repo_settings {
 	int pack_use_sparse;
 	int pack_use_path_walk;
 	enum fetch_negotiation_setting fetch_negotiation_algorithm;
+	enum object_creation_mode object_creation_mode;
 
 	int core_multi_pack_index;
 	int warn_ambiguous_refs; /* lazily loaded via accessor */

-- 
2.50.1.327.g047016eb4a.dirty



  parent reply	other threads:[~2025-07-09 11:21 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09 11:17 [PATCH 00/19] object-file: get rid of `the_repository` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 01/19] object-file: fix -Wsign-compare warnings Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 02/19] object-file: stop using `the_hash_algo` Patrick Steinhardt
2025-07-11  9:52   ` Karthik Nayak
2025-07-09 11:17 ` [PATCH 03/19] object-file: get rid of `the_repository` in `has_loose_object()` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 04/19] object-file: inline `check_and_freshen()` functions Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 05/19] object-file: get rid of `the_repository` when freshening objects Patrick Steinhardt
2025-07-11  9:59   ` Karthik Nayak
2025-07-09 11:17 ` [PATCH 06/19] object-file: get rid of `the_repository` in `loose_object_info()` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 07/19] object-file: get rid of `the_repository` in `finalize_object_file()` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 08/19] loose: write loose objects map via their source Patrick Steinhardt
2025-07-11 10:25   ` Karthik Nayak
2025-07-15 10:50     ` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 09/19] odb: introduce `odb_write_object()` Patrick Steinhardt
2025-07-10 18:39   ` Toon Claes
2025-07-15 10:50     ` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 10/19] object-file: get rid of `the_repository` when writing objects Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 11/19] object-file: inline `for_each_loose_file_in_objdir_buf()` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 12/19] object-file: remove declaration for `for_each_file_in_obj_subdir()` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 13/19] object-file: get rid of `the_repository` in loose object iterators Patrick Steinhardt
2025-07-10 18:41   ` Toon Claes
2025-07-09 11:17 ` [PATCH 14/19] object-file: get rid of `the_repository` in `read_loose_object()` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 15/19] object-file: get rid of `the_repository` in `force_object_loose()` Patrick Steinhardt
2025-07-10 18:42   ` Toon Claes
2025-07-11 10:38   ` Karthik Nayak
2025-07-15 10:50     ` Patrick Steinhardt
2025-07-15 11:36       ` Toon Claes
2025-07-09 11:17 ` [PATCH 16/19] object-file: get rid of `the_repository` in index-related functions Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 17/19] environment: move compression level into repo settings Patrick Steinhardt
2025-07-09 15:26   ` Phillip Wood
2025-07-11 18:55     ` Junio C Hamano
2025-07-15 10:50       ` Patrick Steinhardt
2025-07-15 11:27       ` Patrick Steinhardt
2025-07-15 15:51         ` Phillip Wood
2025-07-15 16:12           ` Patrick Steinhardt
2025-07-16 12:56             ` Patrick Steinhardt
2025-07-17 15:19               ` Phillip Wood
2025-07-17 15:56                 ` Junio C Hamano
2025-07-15 18:50           ` Junio C Hamano
2025-07-17  8:00           ` Ayush Chandekar
2025-07-09 11:17 ` Patrick Steinhardt [this message]
2025-07-09 11:17 ` [PATCH 19/19] object-file: drop USE_THE_REPOSITORY_VARIABLE Patrick Steinhardt
2025-07-17  4:56 ` [PATCH v2 00/16] object-file: get rid of `the_repository` Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 01/16] object-file: fix -Wsign-compare warnings Patrick Steinhardt
2026-04-05  6:56     ` Jeff King
2025-07-17  4:56   ` [PATCH v2 02/16] object-file: stop using `the_hash_algo` Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 03/16] object-file: get rid of `the_repository` in `has_loose_object()` Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 04/16] object-file: inline `check_and_freshen()` functions Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 05/16] object-file: get rid of `the_repository` when freshening objects Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 06/16] object-file: get rid of `the_repository` in `loose_object_info()` Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 07/16] object-file: get rid of `the_repository` in `finalize_object_file()` Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 08/16] loose: write loose objects map via their source Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 09/16] odb: introduce `odb_write_object()` Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 10/16] object-file: get rid of `the_repository` when writing objects Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 11/16] object-file: inline `for_each_loose_file_in_objdir_buf()` Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 12/16] object-file: remove declaration for `for_each_file_in_obj_subdir()` Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 13/16] object-file: get rid of `the_repository` in loose object iterators Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 14/16] object-file: get rid of `the_repository` in `read_loose_object()` Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 15/16] object-file: get rid of `the_repository` in `force_object_loose()` Patrick Steinhardt
2025-07-17  4:56   ` [PATCH v2 16/16] object-file: get rid of `the_repository` in index-related functions Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250709-pks-object-file-wo-the-repository-v1-18-62627b55707f@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).