public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
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>,
	Chandra Pratap <chandrapratap3519@gmail.com>,
	Ayush Jha <kumarayushjha123@gmail.com>
Subject: [PATCH] [RFC][GSoC 2026] builtin/repo: avoid global state in get_layout_bare
Date: Fri,  6 Feb 2026 20:50:02 +0530	[thread overview]
Message-ID: <20260206152002.1244-1-kumarayushjha123@gmail.com> (raw)

The get_layout_bare() function accepts a struct repository *repo
argument but marks it UNUSED and instead relies on
is_bare_repository(), which depends on global state.

As bareness is a per-repository property, this causes the function
to always report the status of the global repository, even when a
specific repository instance is provided.

This change computes the bare status using the passed-in repository
instance (based on core.bare and the absence of a worktree),
thereby removing the dependency on global state.

This patch is sent as an RFC to solicit feedback on whether using
repository-local state here is the preferred approach.

Signed-off-by: Ayush Jha <kumarayushjha123@gmail.com>
---
 builtin/repo.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/builtin/repo.c b/builtin/repo.c
index 0ea045abc1..b2619cc77c 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -35,9 +35,12 @@ struct field {
 	get_value_fn *get_value;
 };
 
-static int get_layout_bare(struct repository *repo UNUSED, struct strbuf *buf)
+static int get_layout_bare(struct repository *repo, struct strbuf *buf)
 {
-	strbuf_addstr(buf, is_bare_repository() ? "true" : "false");
+	int is_bare_cfg = -1;
+	repo_config_get_bool(repo, "core.bare", &is_bare_cfg);
+
+	strbuf_addstr(buf, is_bare_cfg && !repo_get_work_tree(repo) ? "true" : "false");
 	return 0;
 }
 
-- 
2.53.0.windows.1


             reply	other threads:[~2026-02-06 15:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-06 15:20 Ayush Jha [this message]
2026-02-06 18:03 ` [PATCH] [RFC][GSoC 2026] builtin/repo: avoid global state in get_layout_bare Junio C Hamano

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=20260206152002.1244-1-kumarayushjha123@gmail.com \
    --to=kumarayushjha123@gmail.com \
    --cc=ayu.chandekar@gmail.com \
    --cc=chandrapratap3519@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