From: Junio C Hamano <gitster@pobox.com>
To: Joie Joie <soniqjjj@gmail.com>
Cc: Usman Akinyemi <usmanakinyemi202@gmail.com>,
christian.couder@gmail.com, git@vger.kernel.org,
kristofferhaugsbakk@fastmail.com,
Tanga Joris <tangajoris@gmail.com>
Subject: Re: [PATCH] repo: zero-initialize configuration values
Date: Mon, 09 Nov 2026 11:05:43 -0800 [thread overview]
Message-ID: <xmqqo6bxzuyg.fsf@gitster.g> (raw)
In-Reply-To: <CAH=d44fX-LN10TU0ZsuJ_RcxE=6QnKsHrLS4dJorAj3T55TZzA@mail.gmail.com> (Joie Joie's message of "Mon, 9 Nov 2026 15:26:22 +0100")
Joie Joie <soniqjjj@gmail.com> writes:
> 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.
Sounds good, but do not top post ;-)
>
> On Fri, Nov 6, 2026 at 8:36 PM Junio C Hamano <gitster@pobox.com> wrote:
>>
>> 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?
prev parent reply other threads:[~2026-11-09 19:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 11:59 [PATCH] repo: zero-initialize configuration values Joy via GitGitGadget
2026-11-06 14:16 ` Patrick Steinhardt
2026-11-06 16:19 ` Joie Joie
2026-11-06 19:36 ` Junio C Hamano
2026-11-09 14:26 ` Joie Joie
2026-11-09 19:05 ` Junio C Hamano [this message]
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=xmqqo6bxzuyg.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=kristofferhaugsbakk@fastmail.com \
--cc=soniqjjj@gmail.com \
--cc=tangajoris@gmail.com \
--cc=usmanakinyemi202@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