From: shejialuo <shejialuo@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: John Cai via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org, John Cai <johncai86@gmail.com>
Subject: Re: [PATCH 1/3] git: remove is_bare_repository_cfg global variable
Date: Fri, 8 Nov 2024 00:04:21 +0800 [thread overview]
Message-ID: <ZyzlBZnL-K3S7Env@ArchLinux> (raw)
In-Reply-To: <xmqqv7wzsijc.fsf@gitster.g>
On Thu, Nov 07, 2024 at 02:46:15PM +0900, Junio C Hamano wrote:
[snip]
> > int repo_init(struct repository *repo,
> > const char *gitdir,
> > - const char *worktree)
> > + const char *worktree,
> > + int is_bare)
> > {
> > struct repository_format format = REPOSITORY_FORMAT_INIT;
> > memset(repo, 0, sizeof(*repo));
> > @@ -283,6 +288,8 @@ int repo_init(struct repository *repo,
> > repo_set_compat_hash_algo(repo, format.compat_hash_algo);
> > repo_set_ref_storage_format(repo, format.ref_storage_format);
> > repo->repository_format_worktree_config = format.worktree_config;
> > + if (is_bare > 0)
> > + repo->is_bare_cfg = is_bare;
>
> When repo_init() is called with anything other than &the_repo, who
> initializes repo->is_bare_cfg?
I also want to ask this question. Actually, I feel quite strange about
why we need to add a new parameter `is_bare` to `repo_init` function.
For this call:
repo_init(the_repository, git_dir, work_tree, -1);
We add a new field "is_bare_cfg" to the "struct repository". So, at now,
`the_repository` variable should contain the information about whether
the repo is bare(1), is not bare(0) or unknown(-1). However, in this
call, we pass "-1" to the parameter `is_bare` for "repo_init" function.
When I first look at this code, I have thought that we will set
"repo->is_bare_cfg = -1" to indicate that we cannot tell whether the
repo is bare or not. But it just sets the "repo->is_bare_cfg = is_bare"
if `bare > 0`. Junio has already commented on this.
This raises a question: why we need to set up `is_bare_cfg` in the
`repo_init` function? I guess this is because we need to set up other
"struct repository" parameter like the following:
if (repo_init(&alternate, sb.buf, NULL, the_repository->is_bare_cfg) < 0)
And I think it's better for us to use the following way.
alternate->is_bare_cfg = the_repository->is_bare_cfg;
if (repo_init(&alternate, sb.buf, NULL))
And we may create a function called `repo_copy_settings` to set up the
common setting inherited from an existing repo:
repo_copy_settings(alternate, the_repository);
if (repo_init(&alternate, sb.buf, NULL))
I agree that we could put `is_bare_cfg` to "struct repository *". But I
don't agree with the idea that we need to pass `is_bare` to `repo_init`.
I think we should know whether the repo is bare or not before calling
`repo_init`. And from my understanding, this is what we are doing now.
Also, I think we may add a enum type instead of using (-1, 0, 1).
(However, this is not the main point of this patch).
Thanks,
Jialuo
next prev parent reply other threads:[~2024-11-07 16:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-06 20:47 [PATCH 0/3] Remove is_bare_repository_cfg global state John Cai via GitGitGadget
2024-11-06 20:48 ` [PATCH 1/3] git: remove is_bare_repository_cfg global variable John Cai via GitGitGadget
2024-11-07 5:46 ` Junio C Hamano
2024-11-07 16:04 ` shejialuo [this message]
2024-11-08 1:24 ` Junio C Hamano
2024-11-16 12:09 ` shejialuo
2024-11-06 20:48 ` [PATCH 2/3] setup: initialize is_bare_cfg John Cai via GitGitGadget
2024-11-07 6:25 ` Junio C Hamano
2024-11-06 20:48 ` [PATCH 3/3] repository: BUG when is_bare_cfg is not initialized John Cai via GitGitGadget
2024-11-26 8:08 ` [PATCH 0/3] Remove is_bare_repository_cfg global state Junio C Hamano
2024-12-11 23:09 ` (RFH Windows breakage) " 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=ZyzlBZnL-K3S7Env@ArchLinux \
--to=shejialuo@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
--cc=johncai86@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 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.