Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: Tian Yuchen <cat@malon.dev>,
	 git@vger.kernel.org,  Karthik Nayak <karthik.188@gmail.com>,
	 Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH 02/18] setup: stop using `the_repository` in `is_inside_worktree()`
Date: Tue, 19 May 2026 10:22:20 +0900	[thread overview]
Message-ID: <xmqqqzn89os3.fsf@gitster.g> (raw)
In-Reply-To: <agrD4p1AIPtwa5gW@pks.im> (Patrick Steinhardt's message of "Mon, 18 May 2026 09:46:42 +0200")

Patrick Steinhardt <ps@pks.im> writes:

>> I do not offhand know if other code paths that are called from this
>> function are thread-safe, but yeah, this use of file-scope static is
>> not a safe thing to do.
>
> In the current status quo this is a safe conversion to do, as we still
> have the assumption ingrained that this only works for a single repo.
> We were using static variables before, and we're still using static
> variables now.
>
> That being said, I wouldn't mind dropping the static variable if this is
> something we'd rather want to get rid of. It's a smell that I'm not
> particularly happy about myself.
>
> I'll send a revised version in a bit, thanks!

OK.  In the v2 (perhaps v3?) series, I can see the removal of two
static strbuf based "optimizations" is the only change since the
previous round (after merging the previous one to the base of the
new iteration and comparing the result with the new iteration).

Looking very good.  Shall we mark the topic for 'next' now?

Thanks.

diff --git w/setup.c c/setup.c
index 1847111616..6aee839d8c 100644
--- w/setup.c
+++ c/setup.c
@@ -471,17 +471,26 @@ int is_nonbare_repository_dir(struct strbuf *path)
 
 int is_inside_git_dir(struct repository *repo)
 {
-	static struct strbuf buf = STRBUF_INIT;
-	return is_inside_dir(strbuf_realpath(&buf, repo_get_git_dir(repo), 1));
+	struct strbuf buf = STRBUF_INIT;
+	int ret = is_inside_dir(strbuf_realpath(&buf, repo_get_git_dir(repo), 1));
+	strbuf_release(&buf);
+	return ret;
 }
 
 int is_inside_work_tree(struct repository *repo)
 {
-	static struct strbuf buf = STRBUF_INIT;
-	const char *worktree = repo_get_work_tree(repo);
+	struct strbuf buf = STRBUF_INIT;
+	const char *worktree;
+	int ret;
+
+	worktree = repo_get_work_tree(repo);
 	if (!worktree)
 		return 0;
-	return is_inside_dir(strbuf_realpath(&buf, worktree, 1));
+
+	ret = is_inside_dir(strbuf_realpath(&buf, worktree, 1));
+
+	strbuf_release(&buf);
+	return ret;
 }
 
 void setup_work_tree(struct repository *repo)

  reply	other threads:[~2026-05-19  1:22 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20  8:22 [PATCH 00/18] setup: drop uses of `the_repository` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 01/18] setup: replace use of `the_repository` in static functions Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 02/18] setup: stop using `the_repository` in `is_inside_worktree()` Patrick Steinhardt
2026-05-17 16:18   ` Tian Yuchen
2026-05-17 23:41     ` Junio C Hamano
2026-05-18  7:46       ` Patrick Steinhardt
2026-05-19  1:22         ` Junio C Hamano [this message]
2026-05-19  9:50           ` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 03/18] setup: stop using `the_repository` in `is_inside_git_dir()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 04/18] setup: stop using `the_repository` in `prefix_path()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 05/18] setup: stop using `the_repository` in `path_inside_repo()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 06/18] setup: stop using `the_repository` in `verify_filename()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 07/18] setup: stop using `the_repository` in `verify_non_filename()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 08/18] setup: stop using `the_repository` in `enter_repo()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 09/18] setup: stop using `the_repository` in `setup_work_tree()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 10/18] setup: stop using `the_repository` in `set_git_work_tree()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 11/18] setup: stop using `the_repository` in `setup_git_env()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 12/18] setup: stop using `the_repository` in `setup_git_directory_gently()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 13/18] setup: stop using `the_repository` in `setup_git_directory()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 14/18] setup: stop using `the_repository` in `upgrade_repository_format()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 15/18] setup: stop using `the_repository` in `check_repository_format()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 16/18] setup: stop using `the_repository` in `initialize_repository_version()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 17/18] setup: stop using `the_repository` in `create_reference_database()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 18/18] setup: stop using `the_repository` in `init_db()` Patrick Steinhardt
2026-04-20 15:50 ` [PATCH 00/18] setup: drop uses of `the_repository` Elijah Newren
2026-04-21  9:41   ` Patrick Steinhardt
2026-04-20 17:11 ` Junio C Hamano
2026-04-21  9:41   ` Patrick Steinhardt
2026-05-18  9:30 ` [PATCH v2 " Patrick Steinhardt
2026-05-18  9:30   ` [PATCH v2 01/18] setup: replace use of `the_repository` in static functions Patrick Steinhardt
2026-05-19  8:03     ` Karthik Nayak
2026-05-18  9:30   ` [PATCH v2 02/18] setup: stop using `the_repository` in `is_inside_worktree()` Patrick Steinhardt
2026-05-19  8:23     ` Karthik Nayak
2026-05-19  9:47       ` Patrick Steinhardt
2026-05-18  9:30   ` [PATCH v2 03/18] setup: stop using `the_repository` in `is_inside_git_dir()` Patrick Steinhardt
2026-05-19  8:25     ` Karthik Nayak
2026-05-18  9:30   ` [PATCH v2 04/18] setup: stop using `the_repository` in `prefix_path()` Patrick Steinhardt
2026-05-18  9:30   ` [PATCH v2 05/18] setup: stop using `the_repository` in `path_inside_repo()` Patrick Steinhardt
2026-05-18  9:30   ` [PATCH v2 06/18] setup: stop using `the_repository` in `verify_filename()` Patrick Steinhardt
2026-05-18  9:30   ` [PATCH v2 07/18] setup: stop using `the_repository` in `verify_non_filename()` Patrick Steinhardt
2026-05-18  9:30   ` [PATCH v2 08/18] setup: stop using `the_repository` in `enter_repo()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 09/18] setup: stop using `the_repository` in `setup_work_tree()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 10/18] setup: stop using `the_repository` in `set_git_work_tree()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 11/18] setup: stop using `the_repository` in `setup_git_env()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 12/18] setup: stop using `the_repository` in `setup_git_directory_gently()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 13/18] setup: stop using `the_repository` in `setup_git_directory()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 14/18] setup: stop using `the_repository` in `upgrade_repository_format()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 15/18] setup: stop using `the_repository` in `check_repository_format()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 16/18] setup: stop using `the_repository` in `initialize_repository_version()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 17/18] setup: stop using `the_repository` in `create_reference_database()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 18/18] setup: stop using `the_repository` in `init_db()` Patrick Steinhardt
2026-05-19  9:26   ` [PATCH v2 00/18] setup: drop uses of `the_repository` Karthik Nayak
2026-05-19  9:51     ` Patrick Steinhardt
2026-05-19  9:52 ` [PATCH v3 " Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 01/18] setup: replace use of `the_repository` in static functions Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 02/18] setup: stop using `the_repository` in `is_inside_git_dir()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 03/18] setup: stop using `the_repository` in `is_inside_work_tree()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 04/18] setup: stop using `the_repository` in `prefix_path()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 05/18] setup: stop using `the_repository` in `path_inside_repo()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 06/18] setup: stop using `the_repository` in `verify_filename()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 07/18] setup: stop using `the_repository` in `verify_non_filename()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 08/18] setup: stop using `the_repository` in `enter_repo()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 09/18] setup: stop using `the_repository` in `setup_work_tree()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 10/18] setup: stop using `the_repository` in `set_git_work_tree()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 11/18] setup: stop using `the_repository` in `setup_git_env()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 12/18] setup: stop using `the_repository` in `setup_git_directory_gently()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 13/18] setup: stop using `the_repository` in `setup_git_directory()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 14/18] setup: stop using `the_repository` in `upgrade_repository_format()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 15/18] setup: stop using `the_repository` in `check_repository_format()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 16/18] setup: stop using `the_repository` in `initialize_repository_version()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 17/18] setup: stop using `the_repository` in `create_reference_database()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 18/18] setup: stop using `the_repository` in `init_db()` Patrick Steinhardt
  -- strict thread matches above, loose matches on Subject: below --
2026-03-30 13:17 [PATCH 00/18] setup: drop uses of `the_repository` Patrick Steinhardt
2026-03-30 13:17 ` [PATCH 02/18] setup: stop using `the_repository` in `is_inside_worktree()` Patrick Steinhardt
2026-04-09 11:55   ` Karthik Nayak

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=xmqqqzn89os3.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=cat@malon.dev \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    --cc=newren@gmail.com \
    --cc=ps@pks.im \
    /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