Re: [PATCH] repo: zero-initialize configuration values
- From
- Joie Joie <soniqjjj@gmail.com>
- Date
- Nov 9, 2026, 14:26 UTC
- Message-ID
- <CAH=d44fX-LN10TU0ZsuJ_RcxE=6QnKsHrLS4dJorAj3T55TZzA@mail.gmail.com>
- In-Reply-To
- <xmqq7bipiwgt.fsf@gitster.g>
Thanks, Junio.
I hadn't considered using a compound literal here. I was following the existing initialization approach, but your suggestion makes sense, especially given the update to the CodingGuidelines.
I'll look into changing the initialization to use a compound literal while preserving the existing defaults and behavior.
On Fri, Nov 6, 2026 at 8:36 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 50 quoted lines
>
> Patrick Steinhardt <ps@pks.im> writes:
>
> > In any case, the patch is obviously correct and is a good improvement in
> > my opinion. So this looks good to me, thanks.
>
> It however does not look good to me. I would prefer to see
>
> struct foo foo = {0};
>
> if everything is zero initialized, or if there are some members
> initialized to specific values, C99 designated initializers to be
> used:
>
> struct foo foo = {
> /* Comment on this stuff */
> .object_creation_mode = OBJECT_CREATION_MODE,
>
> /* Comment on this other stuff */
> .branch_track = BRANCH_TRACK_REMOTE,
> };
>
> Now this is overwriting the passed in structure members, so how we
> write the initialization is not the whole story.
>
> Since we have avoided assuming the universal availability of the
> more recent "compound literals" syntax, which is:
>
> *cfg = (struct foo) {
> ... an initialization with designated initializers ...
> };
>
> we seem to (ab)use struct assignment, e.g.,
>
> static struct foo foo_template = {
> ... an initialization with designated initializers ...
> };
>
> *cfg = foo_template;
>
> in a few places as a fallback in the existing code (DI is C99,
> struct assignment is C89, so it has been a safer assumption than
> assuming compound literals).
>
> But I do recall we made this update to our CodingGuidelines document.
>
> . since late 2024 with v2.48.0-rc0~20, we have been using compound
> literals, e.g., (struct foo){ .member = value };
>
> So perhaps it is time to switch this to assign a compound literal?