From: Tian Yuchen <a3205153416@gmail.com>
To: "Burak Kaan Karaçay" <bkkaracay@gmail.com>,
"Patrick Steinhardt" <ps@pks.im>
Cc: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>,
git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH v3 1/5] refs: add struct repository parameter to branchname helpers
Date: Fri, 3 Apr 2026 01:48:56 +0800 [thread overview]
Message-ID: <7d8ec377-0555-48d8-b016-6794329932a1@gmail.com> (raw)
In-Reply-To: <ac6K5UnVdw67Rfpy@gmail.com>
On 4/3/26 01:03, Burak Kaan Karaçay wrote:
> Hi,
>
> On Thu, Apr 02, 2026 at 09:27:33AM +0200, Patrick Steinhardt wrote:
>> On Sun, Mar 29, 2026 at 03:46:39PM +0530, Shreyansh Paliwal wrote:
>>> diff --git a/refs.c b/refs.c
>>> index 685a0c247b..5cdc8858c5 100644
>>> --- a/refs.c
>>> +++ b/refs.c
>>> @@ -758,10 +758,10 @@ void copy_branchname(struct strbuf *sb, const
>>> char *name,
>>> strbuf_add(sb, name + used, len - used);
>>> }
>>>
>>> -int check_branch_ref(struct strbuf *sb, const char *name)
>>> +int check_branch_ref(struct repository *repo, struct strbuf *sb,
>>> const char *name)
>>> {
>>> if (startup_info->have_repository)
>>> - copy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
>>> + copy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);
>>> else
>>> strbuf_addstr(sb, name);
>>>
>>
>> I have to agree with Tian's comment on v2, this part here looks wrong. I
>> don't think we should depend on `startup_info` here, but we should
>> exclusively rely on whether or not the caller has passed in a
>> repository. And that will likely require a bit more scrutiny to figure
>> out whether there are any callers that shouldn't pass in a repository
>> because it's not initialized.
>>
>> Alternatively, we could go with Tian's suggestion of checking for `repo
>> && repo->gitdir`.
>>
>> Patrick
>
> This approach actually leads to a bug and segfault in a specific edge
> case when running 'git check-ref-format'. The current tests don't cover
> this scenario, but they can be extended to catch it.
>
> If GIT_DIR is set to a non-existent path,
> 'startup_info->have_repository' becomes '0' but 'repo->gitdir' still
> holds the invalid path. As a result, the code enters the first condition
> and crashes. The case can be tested with this command:
>
> $ git --git-dir='non-existing' check-ref-format --branch @{-1}
>
> Modifying the behavior of 'repo->gitdir' might solve the issue, but I
> belive that falls outside the scope of this patch. After a quick search,
> I found a prophecy from Peff about the 'startup_info->have_repository':
>
> [1] https://lore.kernel.org/
> git/20190806124954.GA13649@sigill.intra.peff.net/
>
> Thanks,
> Burak Kaan Karaçay
You’re absolutely right.
Actually, I’d already spotted the error when I wrote that bit of code,
which is why I said 'I dunno' - simply to give an idea of what I was
trying to achieve. It looks like we’ll have to go with a much uglier
solution. ;)
One possible approach (albeit temporary and useless) is to wrap the code
in a macro or an inline function (in repository.h, I guess?):
> static inline int repo_has_repository(struct repository *repo)
> {
> /*
> * NEEDSWORK...
> */> if (repo == the_repository)
> return startup_info->have_repository;
>
> return repo && repo->gitdir;
> }
This will remove a large amount of startup_info->have_repository...But
that doesn’t solve anything, just as stuffing rubbish into a bin doesn’t
change the fact that it’s rubbish. The 'startup_info->have_repository'
still requires a significant amount of effort to refactor.
So still, I dunno.
Regards, Yuchen
next prev parent reply other threads:[~2026-04-02 17:49 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-25 16:44 [PATCH 0/5] refs: reduce reliance on the_repository global state Shreyansh Paliwal
2026-03-25 16:44 ` [PATCH 1/5] refs: make branchname helpers repository aware Shreyansh Paliwal
2026-03-27 7:49 ` Patrick Steinhardt
2026-03-28 12:45 ` Shreyansh Paliwal
2026-03-25 16:44 ` [PATCH 2/5] refs: make get_files_ref_lock_timeout_ms() repostory aware Shreyansh Paliwal
2026-03-27 7:50 ` Patrick Steinhardt
2026-03-27 9:23 ` Burak Kaan Karaçay
2026-03-28 12:51 ` Shreyansh Paliwal
2026-03-25 16:44 ` [PATCH 3/5] refs: remove the_hash_algo global state Shreyansh Paliwal
2026-03-25 16:44 ` [PATCH 4/5] refs/reftable-backend: drop uses of the_repository Shreyansh Paliwal
2026-03-27 7:50 ` Patrick Steinhardt
2026-03-25 16:44 ` [PATCH 5/5] refs/packed-backend: use ref_store->repo instead " Shreyansh Paliwal
2026-03-28 14:09 ` [PATCH v2 0/5] refs: reduce reliance on the_repository global state Shreyansh Paliwal
2026-03-28 14:09 ` [PATCH v2 1/5] refs: make branchname helpers repository aware Shreyansh Paliwal
2026-03-28 16:54 ` Tian Yuchen
2026-03-29 9:55 ` Shreyansh Paliwal
2026-03-29 15:37 ` Tian Yuchen
2026-03-28 14:09 ` [PATCH v2 2/5] refs: make get_files_ref_lock_timeout_ms() repostory aware Shreyansh Paliwal
2026-03-28 14:09 ` [PATCH v2 3/5] refs: remove the_hash_algo global state Shreyansh Paliwal
2026-03-28 17:03 ` Tian Yuchen
2026-03-28 14:09 ` [PATCH v2 4/5] refs/reftable-backend: drop uses of the_repository Shreyansh Paliwal
2026-03-28 14:09 ` [PATCH v2 5/5] refs/packed-backend: use ref_store->repo instead " Shreyansh Paliwal
2026-03-28 17:08 ` Tian Yuchen
2026-03-29 9:54 ` Shreyansh Paliwal
2026-03-29 10:16 ` [PATCH v3 0/5] replace the_repository with local repository instances Shreyansh Paliwal
2026-03-29 10:16 ` [PATCH v3 1/5] refs: add struct repository parameter to branchname helpers Shreyansh Paliwal
2026-04-02 7:27 ` Patrick Steinhardt
2026-04-02 17:03 ` Burak Kaan Karaçay
2026-04-02 17:48 ` Tian Yuchen [this message]
2026-04-02 18:57 ` Patrick Steinhardt
2026-04-03 10:39 ` Shreyansh Paliwal
2026-03-29 10:16 ` [PATCH v3 2/5] refs: add struct repository parameter in get_files_ref_lock_timeout_ms() Shreyansh Paliwal
2026-03-29 10:16 ` [PATCH v3 3/5] refs: remove the_hash_algo global state Shreyansh Paliwal
2026-03-29 10:16 ` [PATCH v3 4/5] refs/reftable-backend: drop uses of the_repository Shreyansh Paliwal
2026-04-02 7:27 ` Patrick Steinhardt
2026-04-03 10:43 ` Shreyansh Paliwal
2026-03-29 10:16 ` [PATCH v3 5/5] refs/packed-backend: use ref_store->repo instead " Shreyansh Paliwal
2026-04-03 12:08 ` [PATCH v4 0/3] refs: reduce reliance on global state Shreyansh Paliwal
2026-04-03 12:08 ` [PATCH v4 1/3] refs: add struct repository parameter in get_files_ref_lock_timeout_ms() Shreyansh Paliwal
2026-04-03 17:40 ` Tian Yuchen
2026-04-03 12:08 ` [PATCH v4 2/3] refs: remove the_hash_algo global state Shreyansh Paliwal
2026-04-03 12:09 ` [PATCH v4 3/3] refs/reftable-backend: drop uses of the_repository Shreyansh Paliwal
2026-04-04 13:58 ` [PATCH v5 0/3] refs: reduce reliance on global state Shreyansh Paliwal
2026-04-04 13:58 ` [PATCH v5 1/3] refs: add struct repository parameter in get_files_ref_lock_timeout_ms() Shreyansh Paliwal
2026-04-04 13:58 ` [PATCH v5 2/3] refs: remove the_hash_algo global state Shreyansh Paliwal
2026-04-04 13:58 ` [PATCH v5 3/3] refs/reftable-backend: drop uses of the_repository Shreyansh Paliwal
2026-04-08 8:46 ` [PATCH v5 0/3] refs: reduce reliance on global state Patrick Steinhardt
2026-04-08 17:09 ` 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=7d8ec377-0555-48d8-b016-6794329932a1@gmail.com \
--to=a3205153416@gmail.com \
--cc=bkkaracay@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=ps@pks.im \
--cc=shreyanshpaliwalcmsmn@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