Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: Joy via GitGitGadget <gitgitgadget@gmail.com>,
	 git@vger.kernel.org,
	"Kristoffer Haugsbakk@imap.fastmail.com>"
	<kristofferhaugsbakk@fastmail.com>,
	 "Christian Couder>" <christian.couder@gmail.com>,
	 "Usman Akinyemi@imap.fastmail.com>" <usmanakinyemi202@gmail.com>,
	 Joie Joie <soniqjjj@gmail.com>,
	 Tanga Joris <tangajoris@gmail.com>
Subject: Re: [PATCH] repo: zero-initialize configuration values
Date: Fri, 06 Nov 2026 11:36:02 -0800	[thread overview]
Message-ID: <xmqq7bipiwgt.fsf@gitster.g> (raw)
In-Reply-To: <au3hVGPuDyGVwOw8@pks.im> (Patrick Steinhardt's message of "Fri, 6 Nov 2026 15:16:52 +0100")

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?

      parent reply	other threads:[~2026-11-06 19:36 UTC|newest]

Thread overview: 4+ 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 [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=xmqq7bipiwgt.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=kristofferhaugsbakk@fastmail.com \
    --cc=ps@pks.im \
    --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