git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Olga Pilipenco via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, "Patrick Steinhardt" <ps@pks.im>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"René Scharfe" <l.s.r@web.de>,
	"Olga Pilipenco" <olga.pilipenco@shopify.com>
Subject: Re: [PATCH v3] worktree: detect from secondary worktree if main worktree is bare
Date: Fri, 31 Jan 2025 11:19:34 -0800	[thread overview]
Message-ID: <xmqqcyg294ft.fsf@gitster.g> (raw)
In-Reply-To: <pull.1829.v3.git.1738346881907.gitgitgadget@gmail.com> (Olga Pilipenco via GitGitGadget's message of "Fri, 31 Jan 2025 18:08:01 +0000")

"Olga Pilipenco via GitGitGadget" <gitgitgadget@gmail.com> writes:

> +/*
> +* When in a secondary worktree, and when extensions.worktreeConfig
> +* is true, only $commondir/config and $commondir/worktrees/<id>/
> +* config.worktree are consulted, hence any core.bare=true setting in
> +* $commondir/config.worktree gets overlooked. Thus, check it manually
> +* to determine if the repository is bare.
> +*/
> +static int is_main_worktree_bare(struct repository *repo)
> +{
> +	int bare = 0;
> +	struct config_set cs = {0};
> +	char *worktree_config = xstrfmt("%s/config.worktree", repo_get_common_dir(repo));
> +
> +	git_configset_init(&cs);
> +	git_configset_add_file(&cs, worktree_config);
> +	git_configset_get_bool(&cs, "core.bare", &bare);
> +
> +	git_configset_clear(&cs);
> +	free(worktree_config);
> +	return bare;
> +}

That is nicely described.

>  /**
>   * get the main worktree
>   */
> @@ -79,16 +101,11 @@ static struct worktree *get_main_worktree(int skip_reading_head)
>  	CALLOC_ARRAY(worktree, 1);
>  	worktree->repo = the_repository;
>  	worktree->path = strbuf_detach(&worktree_path, NULL);
> -	/*
> -	 * NEEDSWORK: If this function is called from a secondary worktree and
> -	 * config.worktree is present, is_bare_repository_cfg will reflect the
> -	 * contents of config.worktree, not the contents of the main worktree.
> -	 * This means that worktree->is_bare may be set to 0 even if the main
> -	 * worktree is configured to be bare.
> -	 */
> -	worktree->is_bare = (is_bare_repository_cfg == 1) ||
> -		is_bare_repository();
>  	worktree->is_current = is_current_worktree(worktree);
> +	worktree->is_bare = (is_bare_repository_cfg == 1) ||
> +		is_bare_repository() ||
> +		(!worktree->is_current && is_main_worktree_bare(the_repository));

Is "this worktree does not have is_current bit set" equivalent to
"this worktree is the main one, so is_main_worktree_bare() needs to
be consulted"?  That linkage between "the is_current bit unset" and
"is the main worktree" is not obvious to me.

Thanks.

  reply	other threads:[~2025-01-31 19:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-15  6:52 [PATCH] worktree: detect from secondary worktree if main worktree is bare Olga Pilipenco via GitGitGadget
2025-01-16 21:35 ` [PATCH v2] " Olga Pilipenco via GitGitGadget
2025-01-19 22:30   ` Eric Sunshine
2025-01-28 21:44     ` Olga Pilipenco
2025-01-29 13:41       ` Eric Sunshine
2025-01-29 17:08         ` Junio C Hamano
     [not found]         ` <F15C12AB-2238-4553-AFA5-18277B18CE5A@shopify.com>
2025-01-30 14:32           ` Eric Sunshine
2025-01-30 14:44             ` Eric Sunshine
2025-01-31  7:05               ` Olga Pilipenco
2025-01-31 13:28                 ` Eric Sunshine
2025-01-31 18:08   ` [PATCH v3] " Olga Pilipenco via GitGitGadget
2025-01-31 19:19     ` Junio C Hamano [this message]
2025-01-31 19:26       ` Junio C Hamano
2025-01-31 20:11         ` Olga Pilipenco
2025-01-31 20:20           ` Junio C Hamano
2025-02-04 19:03             ` Olga Pilipenco
2025-02-04 19:43               ` Junio C Hamano
2025-02-04 20:33                 ` Olga Pilipenco
2025-02-05  6:30     ` [PATCH v4] " Olga Pilipenco via GitGitGadget

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=xmqqcyg294ft.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=l.s.r@web.de \
    --cc=olga.pilipenco@shopify.com \
    --cc=ps@pks.im \
    --cc=sunshine@sunshineco.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;
as well as URLs for NNTP newsgroup(s).