[PATCH 18/19] environment: move object creation mode into repo settings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>
---
 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





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux