From: Ayush Jha <kumarayushjha123@gmail.com>
To: git@vger.kernel.org
Cc: Christian Couder <christian.couder@gmail.com>,
Karthik Nayak <karthik.188@gmail.com>,
Justin Tobler <jltobler@gmail.com>,
Ayush Chandekar <ayu.chandekar@gmail.com>,
Siddharth Asthana <siddharthasthana31@gmail.com>,
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>,
Ayush Jha <kumarayushjha123@gmail.com>
Subject: [RFC GSoC PATCH v3 1/2] repo-settings: add repo_settings_get_is_bare
Date: Sun, 8 Feb 2026 13:29:04 +0530 [thread overview]
Message-ID: <20260208075905.1807-1-kumarayushjha123@gmail.com> (raw)
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
next reply other threads:[~2026-02-08 7:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-08 7:59 Ayush Jha [this message]
2026-02-08 7:59 ` [RFC GSoC PATCH v3 2/2] attr: use local repository state in read_attr Ayush Jha
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=20260208075905.1807-1-kumarayushjha123@gmail.com \
--to=kumarayushjha123@gmail.com \
--cc=ayu.chandekar@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=jltobler@gmail.com \
--cc=karthik.188@gmail.com \
--cc=lucasseikioshiro@gmail.com \
--cc=siddharthasthana31@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