[GSOC PATCH v2 1/2] environment: move access to "core.attributesfile" into repo settings

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

 



When handling multiple repositories within the same process, relying on
global state for accessing the "core.attributesfile" configuration can
lead to incorrect values being used. It also makes it harder to isolate
repositories and hinders the libification of git.

Store the "core.attributesfile" configuration in the `repo_settings`
instead of relying on the global state. Add a new function
`repo_settings_get_attributesfile_path()` to retrieve this setting in a
repository-scoped manner.

Signed-off-by: Ayush Chandekar <ayu.chandekar@xxxxxxxxx>
---
 config.c        |  5 -----
 environment.c   |  1 -
 environment.h   |  1 -
 repo-settings.c | 11 +++++++++++
 repo-settings.h |  3 +++
 5 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/config.c b/config.c
index 658569af08..b52ad3e3ad 100644
--- a/config.c
+++ b/config.c
@@ -1432,11 +1432,6 @@ static int git_default_core_config(const char *var, const char *value,
 		return 0;
 	}
 
-	if (!strcmp(var, "core.attributesfile")) {
-		FREE_AND_NULL(git_attributes_file);
-		return git_config_pathname(&git_attributes_file, var, value);
-	}
-
 	if (!strcmp(var, "core.bare")) {
 		is_bare_repository_cfg = git_config_bool(var, value);
 		return 0;
diff --git a/environment.c b/environment.c
index 9e4c7781be..d7bf911ec5 100644
--- a/environment.c
+++ b/environment.c
@@ -42,7 +42,6 @@ char *git_commit_encoding;
 char *git_log_output_encoding;
 char *apply_default_whitespace;
 char *apply_default_ignorewhitespace;
-char *git_attributes_file;
 int zlib_compression_level = Z_BEST_SPEED;
 int pack_compression_level = Z_DEFAULT_COMPRESSION;
 int fsync_object_files = -1;
diff --git a/environment.h b/environment.h
index 45e690f203..b7860eed3a 100644
--- a/environment.h
+++ b/environment.h
@@ -149,7 +149,6 @@ extern int assume_unchanged;
 extern int warn_on_object_refname_ambiguity;
 extern char *apply_default_whitespace;
 extern char *apply_default_ignorewhitespace;
-extern char *git_attributes_file;
 extern int zlib_compression_level;
 extern int pack_compression_level;
 extern size_t packed_git_window_size;
diff --git a/repo-settings.c b/repo-settings.c
index 67e9cfd2e6..17e60aa0d6 100644
--- a/repo-settings.c
+++ b/repo-settings.c
@@ -5,6 +5,7 @@
 #include "midx.h"
 #include "pack-objects.h"
 #include "setup.h"
+#include "path.h"
 
 static void repo_cfg_bool(struct repository *r, const char *key, int *dest,
 			  int def)
@@ -148,6 +149,7 @@ void repo_settings_clear(struct repository *r)
 	struct repo_settings empty = REPO_SETTINGS_INIT;
 	FREE_AND_NULL(r->settings.fsmonitor);
 	FREE_AND_NULL(r->settings.hooks_path);
+	FREE_AND_NULL(r->settings.git_attributes_file);
 	r->settings = empty;
 }
 
@@ -207,3 +209,12 @@ void repo_settings_reset_shared_repository(struct repository *repo)
 {
 	repo->settings.shared_repository_initialized = 0;
 }
+
+const char *repo_settings_get_attributesfile_path(struct repository *repo)
+{
+	if (!repo->settings.git_attributes_file) {
+		if (repo_config_get_pathname(repo, "core.attributesfile", &repo->settings.git_attributes_file))
+			repo->settings.git_attributes_file = xdg_config_home("attributes");
+	}
+	return repo->settings.git_attributes_file;
+}
diff --git a/repo-settings.h b/repo-settings.h
index ddc11967e0..58dadd9dae 100644
--- a/repo-settings.h
+++ b/repo-settings.h
@@ -66,6 +66,7 @@ struct repo_settings {
 	size_t packed_git_limit;
 
 	char *hooks_path;
+	char *git_attributes_file;
 };
 #define REPO_SETTINGS_INIT { \
 	.shared_repository = -1, \
@@ -92,5 +93,7 @@ const char *repo_settings_get_hooks_path(struct repository *repo);
 int repo_settings_get_shared_repository(struct repository *repo);
 void repo_settings_set_shared_repository(struct repository *repo, int value);
 void repo_settings_reset_shared_repository(struct repository *repo);
+/* Read the value for "core.attributesfile". */
+const char *repo_settings_get_attributesfile_path(struct repository *repo);
 
 #endif /* REPO_SETTINGS_H */
-- 
2.48.GIT





[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