public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC GSoC PATCH v3 1/2] repo-settings: add repo_settings_get_is_bare
@ 2026-02-08  7:59 Ayush Jha
  2026-02-08  7:59 ` [RFC GSoC PATCH v3 2/2] attr: use local repository state in read_attr Ayush Jha
  0 siblings, 1 reply; 2+ messages in thread
From: Ayush Jha @ 2026-02-08  7:59 UTC (permalink / raw)
  To: git
  Cc: Christian Couder, Karthik Nayak, Justin Tobler, Ayush Chandekar,
	Siddharth Asthana, Lucas Seiki Oshiro, Ayush Jha

The is_bare_repository() function relies on the global the_repository
variable, making it unsuitable for use in library code that may operate
on arbitrary repositories. Additionally, calling repo_config_get_bool
repeatedly to check core.bare can be expensive if done frequently.

Add a lazy-loaded is_bare field to struct repo_settings and expose
it via repo_settings_get_is_bare(). This allows call sites to check
bareness cheaply and correctly using a repository context.

Signed-off-by: Ayush Jha <kumarayushjha123@gmail.com>
---
 repo-settings.c | 12 ++++++++++++
 repo-settings.h |  5 +++++
 2 files changed, 17 insertions(+)

diff --git a/repo-settings.c b/repo-settings.c
index 208e09ff17..fb0af993ee 100644
--- a/repo-settings.c
+++ b/repo-settings.c
@@ -233,3 +233,15 @@ void repo_settings_reset_shared_repository(struct repository *repo)
 {
 	repo->settings.shared_repository_initialized = 0;
 }
+
+int repo_settings_get_is_bare(struct repository *repo)
+{
+	if (repo->settings.is_bare < 0) {
+		int is_bare_cfg = 0;
+		if (repo_config_get_bool(repo, "core.bare", &is_bare_cfg))
+			repo->settings.is_bare = !repo_get_work_tree(repo);
+		else
+			repo->settings.is_bare = is_bare_cfg && !repo_get_work_tree(repo);
+	}
+	return repo->settings.is_bare;
+}
diff --git a/repo-settings.h b/repo-settings.h
index cad9c3f0cc..bde87f9f29 100644
--- a/repo-settings.h
+++ b/repo-settings.h
@@ -26,6 +26,7 @@ enum log_refs_config {
 struct repo_settings {
 	int initialized;
 
+	int is_bare;
 	int core_commit_graph;
 	int commit_graph_generation_version;
 	int commit_graph_changed_paths_version;
@@ -74,6 +75,7 @@ struct repo_settings {
 #define REPO_SETTINGS_INIT { \
 	.shared_repository = -1, \
 	.index_version = -1, \
+	.is_bare = -1, \
 	.core_untracked_cache = UNTRACKED_CACHE_KEEP, \
 	.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \
 	.warn_ambiguous_refs = -1, \
@@ -102,4 +104,7 @@ 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 and set the value for "core.bare". */
+int repo_settings_get_is_bare(struct repository *repo);
+
 #endif /* REPO_SETTINGS_H */
-- 
2.53.0.windows.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [RFC GSoC PATCH v3 2/2] attr: use local repository state in read_attr
  2026-02-08  7:59 [RFC GSoC PATCH v3 1/2] repo-settings: add repo_settings_get_is_bare Ayush Jha
@ 2026-02-08  7:59 ` Ayush Jha
  0 siblings, 0 replies; 2+ messages in thread
From: Ayush Jha @ 2026-02-08  7:59 UTC (permalink / raw)
  To: git
  Cc: Christian Couder, Karthik Nayak, Justin Tobler, Ayush Chandekar,
	Siddharth Asthana, Lucas Seiki Oshiro, Ayush Jha

The read_attr function currently relies on is_bare_repository() to decide whether to check the index or working tree for attributes. This function implicitly depends on the_repository, which is incorrect for library code handling secondary repositories.

Update read_attr to use the new  repo_settings_get_is_bare(istate->repo)
helper. This ensures the logic respects the context of the specific repository associated with the index, while also benefiting from the lazy-loading optimization added in the previous commit.

Signed-off-by: Ayush Jha <kumarayushjha123@gmail.com>
---
 attr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/attr.c b/attr.c
index 4999b7e09d..2e1cde4615 100644
--- a/attr.c
+++ b/attr.c
@@ -23,6 +23,7 @@
 #include "refs.h"
 #include "revision.h"
 #include "odb.h"
+#include "repo-settings.h"
 #include "setup.h"
 #include "thread-utils.h"
 #include "tree-walk.h"
@@ -848,7 +849,7 @@ static struct attr_stack *read_attr(struct index_state *istate,
 		res = read_attr_from_index(istate, path, flags);
 	} else if (tree_oid) {
 		res = read_attr_from_blob(istate, tree_oid, path, flags);
-	} else if (!is_bare_repository()) {
+	} else if (!repo_settings_get_is_bare(istate->repo)) {
 		if (direction == GIT_ATTR_CHECKOUT) {
 			res = read_attr_from_index(istate, path, flags);
 			if (!res)
-- 
2.53.0.windows.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-02-08  7:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-08  7:59 [RFC GSoC PATCH v3 1/2] repo-settings: add repo_settings_get_is_bare Ayush Jha
2026-02-08  7:59 ` [RFC GSoC PATCH v3 2/2] attr: use local repository state in read_attr Ayush Jha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox