git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ayush Chandekar <ayu.chandekar@gmail.com>
To: ayu.chandekar@gmail.com
Cc: git@vger.kernel.org, ps@pks.im, shejialuo@gmail.com, gitster@pobox.com
Subject: [GSOC PATCH v2 1/2] environment: move access to "core.attributesfile" into repo settings
Date: Mon, 10 Mar 2025 20:40:47 +0530	[thread overview]
Message-ID: <20250310151048.69825-2-ayu.chandekar@gmail.com> (raw)
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


  reply	other threads:[~2025-03-10 15:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-09 15:33 [PATCH] environment: move access to "core.attributesfile" into repo settings Ayush Chandekar
2025-03-10  7:05 ` Patrick Steinhardt
2025-03-10  9:07   ` Ayush Chandekar
2025-03-10 16:16   ` Junio C Hamano
2025-03-10 17:21     ` Ayush Chandekar
2025-03-10 19:25       ` Junio C Hamano
2025-03-10 15:10 ` [GSOC PATCH v2 0/2] Stop depending on `the_repository` for core.attributesfile Ayush Chandekar
2025-03-10 15:10   ` Ayush Chandekar [this message]
2025-03-10 21:11     ` [GSOC PATCH v2 1/2] environment: move access to "core.attributesfile" into repo settings Karthik Nayak
2025-03-10 15:10   ` [GSOC PATCH v2 2/2] attr: use `repo_settings_get_attributesfile_path()` and update callers Ayush Chandekar
2025-03-10 21:17     ` Karthik Nayak
2025-03-10 23:08       ` Junio C Hamano
2025-03-11 17:41       ` Ayush Chandekar
2025-03-11 14:39     ` shejialuo
2025-03-11 17:03       ` Junio C Hamano
2025-03-11 17:20       ` Ayush Chandekar

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

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

  git send-email \
    --in-reply-to=20250310151048.69825-2-ayu.chandekar@gmail.com \
    --to=ayu.chandekar@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ps@pks.im \
    --cc=shejialuo@gmail.com \
    /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.
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 NNTP newsgroup(s).