git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] repo: zero-initialize configuration values

From
JJJoie 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?
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 6 in “repo: zero-initialize configuration values”
  1. repo: zero-initialize configuration valuesJoy via GitGitGadget, Nov 6, 2026
  2. Patrick SteinhardtNov 6, 2026
  3. Joie JoieNov 6, 2026
  4. Junio C HamanoNov 6, 2026
  5. Joie JoieNov 9, 2026
  6. Junio C HamanoNov 9, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.