{"thread":{"id":"64944","subject":"[RFC GSoC PATCH v3 1/2] repo-settings: add repo_settings_get_is_bare","startedAt":"2026-02-08T07:59:20Z","lastAt":"2026-02-08T07:59:27Z","messageCount":2,"participants":["Ayush Jha"],"isPatch":true,"patchVersion":3,"patchTotal":2},"messages":[{"id":"535469","messageId":"20260208075905.1807-1-kumarayushjha123@gmail.com","threadId":"64944","inReplyTo":null,"subject":"[RFC GSoC PATCH v3 1/2] repo-settings: add repo_settings_get_is_bare","fromName":"Ayush Jha","fromEmail":"kumarayushjha123@gmail.com","sentAt":"2026-02-08T07:59:04Z","receivedAt":"2026-02-08T07:59:20Z","isPatch":true,"sender":{"key":"kumarayushjha123@gmail.com","avatar":null},"body":"The is_bare_repository() function relies on the global the_repository\nvariable, making it unsuitable for use in library code that may operate\non arbitrary repositories. Additionally, calling repo_config_get_bool\nrepeatedly to check core.bare can be expensive if done frequently.\n\nAdd a lazy-loaded is_bare field to struct repo_settings and expose\nit via repo_settings_get_is_bare(). This allows call sites to check\nbareness cheaply and correctly using a repository context.\n\nSigned-off-by: Ayush Jha <kumarayushjha123@gmail.com>\n---\n repo-settings.c | 12 ++++++++++++\n repo-settings.h |  5 +++++\n 2 files changed, 17 insertions(+)\n\ndiff --git a/repo-settings.c b/repo-settings.c\nindex 208e09ff17..fb0af993ee 100644\n--- a/repo-settings.c\n+++ b/repo-settings.c\n@@ -233,3 +233,15 @@ void repo_settings_reset_shared_repository(struct repository *repo)\n {\n \trepo->settings.shared_repository_initialized = 0;\n }\n+\n+int repo_settings_get_is_bare(struct repository *repo)\n+{\n+\tif (repo->settings.is_bare < 0) {\n+\t\tint is_bare_cfg = 0;\n+\t\tif (repo_config_get_bool(repo, \"core.bare\", &is_bare_cfg))\n+\t\t\trepo->settings.is_bare = !repo_get_work_tree(repo);\n+\t\telse\n+\t\t\trepo->settings.is_bare = is_bare_cfg && !repo_get_work_tree(repo);\n+\t}\n+\treturn repo->settings.is_bare;\n+}\ndiff --git a/repo-settings.h b/repo-settings.h\nindex cad9c3f0cc..bde87f9f29 100644\n--- a/repo-settings.h\n+++ b/repo-settings.h\n@@ -26,6 +26,7 @@ enum log_refs_config {\n struct repo_settings {\n \tint initialized;\n \n+\tint is_bare;\n \tint core_commit_graph;\n \tint commit_graph_generation_version;\n \tint commit_graph_changed_paths_version;\n@@ -74,6 +75,7 @@ struct repo_settings {\n #define REPO_SETTINGS_INIT { \\\n \t.shared_repository = -1, \\\n \t.index_version = -1, \\\n+\t.is_bare = -1, \\\n \t.core_untracked_cache = UNTRACKED_CACHE_KEEP, \\\n \t.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \\\n \t.warn_ambiguous_refs = -1, \\\n@@ -102,4 +104,7 @@ int repo_settings_get_shared_repository(struct repository *repo);\n void repo_settings_set_shared_repository(struct repository *repo, int value);\n void repo_settings_reset_shared_repository(struct repository *repo);\n \n+/* Read and set the value for \"core.bare\". */\n+int repo_settings_get_is_bare(struct repository *repo);\n+\n #endif /* REPO_SETTINGS_H */\n-- \n2.53.0.windows.1\n\n"},{"id":"535470","messageId":"20260208075905.1807-2-kumarayushjha123@gmail.com","threadId":"64944","inReplyTo":"20260208075905.1807-1-kumarayushjha123@gmail.com","subject":"[RFC GSoC PATCH v3 2/2] attr: use local repository state in read_attr","fromName":"Ayush Jha","fromEmail":"kumarayushjha123@gmail.com","sentAt":"2026-02-08T07:59:05Z","receivedAt":"2026-02-08T07:59:27Z","isPatch":true,"sender":{"key":"kumarayushjha123@gmail.com","avatar":null},"body":"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.\n\nUpdate read_attr to use the new  repo_settings_get_is_bare(istate->repo)\nhelper. 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.\n\nSigned-off-by: Ayush Jha <kumarayushjha123@gmail.com>\n---\n attr.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/attr.c b/attr.c\nindex 4999b7e09d..2e1cde4615 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -23,6 +23,7 @@\n #include \"refs.h\"\n #include \"revision.h\"\n #include \"odb.h\"\n+#include \"repo-settings.h\"\n #include \"setup.h\"\n #include \"thread-utils.h\"\n #include \"tree-walk.h\"\n@@ -848,7 +849,7 @@ static struct attr_stack *read_attr(struct index_state *istate,\n \t\tres = read_attr_from_index(istate, path, flags);\n \t} else if (tree_oid) {\n \t\tres = read_attr_from_blob(istate, tree_oid, path, flags);\n-\t} else if (!is_bare_repository()) {\n+\t} else if (!repo_settings_get_is_bare(istate->repo)) {\n \t\tif (direction == GIT_ATTR_CHECKOUT) {\n \t\t\tres = read_attr_from_index(istate, path, flags);\n \t\t\tif (!res)\n-- \n2.53.0.windows.1\n\n"}]}