Re: [PATCH] promisor-remote: fix crash without a repository
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 16, 2026, 15:29 UTC
- Message-ID
- <xmqqtslgn6ad.fsf@gitster.g>
- In-Reply-To
- <avqkLnnMwBNeWWtK@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
> I was wondering myself whether a better fix would be to start passing > down the repository and then detect this case by checking for `!repo` > instead.
That would be the most sensible way forward, as it would potentially allow us to help more code paths free from the_repository.
Show 7 quoted lines
> From my point of view it's nowadays a bit of a code smell to > check whether the passed repository itself is actually an initialized > one or not: if we aren't operating inside a repository, then the caller > shouldn't pass one. > > That may be a bigger refactoring though, so depending on its scope I'm > happy to live with the easier fix for now.
Yes.
Show 13 quoted lines
>> + /*
>> + * "ls-remote" has no business talking about promisors, and worse yet,
>> + * it can be run outside a repository.
>> + */
>> + if (!repo->gitdir) {
>> + if (accepted_out)
>> + *accepted_out = NULL;
>> + return;
>> + }
>
> But in any case, we should also detect the case where `!repo`, I'd say.
> Otherwise we'll have to adapt this code again once this funciton's call
> chains get rid of `the_repository`.Yes, again, but as long as we have sufficient test coverage right now, the dereference repo->gitdir would immediately segfault when our caller stops passing the_repository and instead passes NULL when it notices that we are not in a repository ;-)