From: Justin Tobler <jltobler@gmail.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 3/7] setup: remove global `git_work_tree_cfg` variable
Date: Wed, 10 Jun 2026 16:52:12 -0500 [thread overview]
Message-ID: <ainXM84fGggtEZzM@denethor> (raw)
In-Reply-To: <20260610-b4-pks-setup-drop-global-state-v1-3-5dff3eec8f06@pks.im>
On 26/06/10 08:56AM, Patrick Steinhardt wrote:
> The global `git_work_tree_cfg` variable used to be modified by both
> "setup.c" and by "builtin/init-db.c". We have refactored the latter user
> to not use that variable at all anymore in a preceding commit, which
> makes "setup.c" the only remaining user.
>
> Even for "setup.c" it is unnecessary though, as we only ever set it to
> the value we have stored in the discovered repository format. The
> consequence is that we only ever set it in case we already have it set
> to the same value in our discovered repository format, which makes it
> redundant.
Nice. I was wondering in the first patch if there would really be any
need to keep `git_work_tree_cfg` around here at all. Makes sense to me
to just set the repository worktree directly.
> Refactor the code so that we instead use the worktree configuration as
> discovered via the repository format. Drop the global variable.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> setup.c | 28 +++++++++++-----------------
> 1 file changed, 11 insertions(+), 17 deletions(-)
>
> diff --git a/setup.c b/setup.c
> index 52228b42a1..71fc6b33da 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -31,9 +31,6 @@ enum allowed_bare_repo {
> ALLOWED_BARE_REPO_ALL,
> };
>
> -/* This is set by setup_git_directory_gently() and/or git_default_config() */
> -static char *git_work_tree_cfg;
> -
> static struct startup_info the_startup_info;
> struct startup_info *startup_info = &the_startup_info;
> const char *tmp_original_cwd;
> @@ -799,13 +796,10 @@ static int check_repository_format_gently(const char *gitdir,
> }
>
> if (!has_common) {
> - if (candidate->is_bare != -1) {
> + if (candidate->is_bare != -1)
> is_bare_repository_cfg = candidate->is_bare;
> - }
> - if (candidate->work_tree) {
> - free(git_work_tree_cfg);
> - git_work_tree_cfg = xstrdup(candidate->work_tree);
Ok, we no longer set `git_work_tree_cfg` in favor of just relying on the
worktree specified in the repository format.
> - }
> + } else {
> + FREE_AND_NULL(candidate->work_tree);
Huh, we were not previously freeing the worktree here, but I assume this
to avoid a resource leak?
The remainder of this patch replaces `git_work_tree_cfg` usage with the
repository format worktree and looks good.
-Justin
next prev parent reply other threads:[~2026-06-10 21:52 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-10 6:56 [PATCH 0/7] setup: drop global state Patrick Steinhardt
2026-06-10 6:56 ` [PATCH 1/7] builtin/init: stop modifying global `git_work_tree_cfg` variable Patrick Steinhardt
2026-06-10 21:15 ` Justin Tobler
2026-06-10 6:56 ` [PATCH 2/7] builtin/init: simplify logic to configure worktree Patrick Steinhardt
2026-06-10 21:29 ` Justin Tobler
2026-06-10 6:56 ` [PATCH 3/7] setup: remove global `git_work_tree_cfg` variable Patrick Steinhardt
2026-06-10 21:52 ` Justin Tobler [this message]
2026-06-11 6:36 ` Patrick Steinhardt
2026-06-10 6:56 ` [PATCH 4/7] builtin/init: stop modifying `is_bare_repository_cfg` Patrick Steinhardt
2026-06-10 6:56 ` [PATCH 5/7] environment: split up concerns of `is_bare_repository_cfg` Patrick Steinhardt
2026-06-10 22:22 ` Justin Tobler
2026-06-10 6:56 ` [PATCH 6/7] environment: stop using `the_repository` in `is_bare_repository()` Patrick Steinhardt
2026-06-10 6:56 ` [PATCH 7/7] treewide: drop USE_THE_REPOSITORY_VARIABLE Patrick Steinhardt
2026-06-10 22:26 ` Justin Tobler
2026-06-11 6:44 ` [PATCH v2 0/7] setup: drop global state Patrick Steinhardt
2026-06-11 6:44 ` [PATCH v2 1/7] builtin/init: stop modifying global `git_work_tree_cfg` variable Patrick Steinhardt
2026-06-11 6:44 ` [PATCH v2 2/7] builtin/init: simplify logic to configure worktree Patrick Steinhardt
2026-06-11 6:44 ` [PATCH v2 3/7] setup: remove global `git_work_tree_cfg` variable Patrick Steinhardt
2026-06-11 6:44 ` [PATCH v2 4/7] builtin/init: stop modifying `is_bare_repository_cfg` Patrick Steinhardt
2026-06-11 6:44 ` [PATCH v2 5/7] environment: split up concerns of `is_bare_repository_cfg` Patrick Steinhardt
2026-06-11 6:44 ` [PATCH v2 6/7] environment: stop using `the_repository` in `is_bare_repository()` Patrick Steinhardt
2026-06-11 6:44 ` [PATCH v2 7/7] treewide: drop USE_THE_REPOSITORY_VARIABLE Patrick Steinhardt
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=ainXM84fGggtEZzM@denethor \
--to=jltobler@gmail.com \
--cc=git@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.