git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Ayush Chandekar <ayu.chandekar@gmail.com>
Date
Mar 10, 2025, 15:10 UTC
Message-ID
<20250310151048.69825-2-ayu.chandekar@gmail.com>
In-Reply-To
<20250310151048.69825-1-ayu.chandekar@gmail.com>

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@gmail.com>
---
 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
Previous: Ayush ChandekarNext: Karthik Nayak
Message 8 of 18 in “environment: move access to "core.attributesfile" into repo settings”
  1. environment: move access to "core.attributesfile" into repo settingsAyush Chandekar, Mar 9, 2025
  2. Patrick SteinhardtMar 10, 2025
  3. Ayush ChandekarMar 10, 2025
  4. Junio C HamanoMar 10, 2025
  5. Ayush ChandekarMar 10, 2025
  6. Junio C HamanoMar 10, 2025
  7. 0/2 Stop depending on `the_repository` for core.attributesfileAyush Chandekar, Mar 10, 2025
  8. 1/2 environment: move access to "core.attributesfile" into repo settingsAyush Chandekar, Mar 10, 2025
  9. Karthik NayakMar 10, 2025
  10. 2/2 attr: use `repo_settings_get_attributesfile_path()` and update callersAyush Chandekar, Mar 10, 2025
  11. Karthik NayakMar 10, 2025
  12. Junio C HamanoMar 10, 2025
  13. Ayush ChandekarMar 11, 2025
  14. shejialuoMar 11, 2025
  15. Junio C HamanoMar 11, 2025
  16. Ayush ChandekarMar 11, 2025
  17. Outreachy intern: Request for the completion of this seriesOlamide Caleb Bello, Dec 8, 2025
  18. Bello OlamideDec 9, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.