From: Junio C Hamano <gitster@pobox.com>
To: kristofferhaugsbakk@fastmail.com
Cc: git@vger.kernel.org, Kristoffer Haugsbakk <code@khaugsbakk.name>
Subject: Re: [PATCH 2/4] format-rev: factor option variables into a struct
Date: Thu, 13 Aug 2026 11:21:57 -0700 [thread overview]
Message-ID: <xmqqfr0hswxm.fsf@gitster.g> (raw)
In-Reply-To: <factor_opts_into_struct.b82@msgid.xyz> (kristofferhaugsbakk@fastmail.com's message of "Thu, 13 Aug 2026 19:23:58 +0200")
kristofferhaugsbakk@fastmail.com writes:
> From: Kristoffer Haugsbakk <code@khaugsbakk.name>
>
> We will in two commits add three more options to this command.
> Let’s prepare for that by moving option variables into a struct
> so that we get less local variables.
>
> This allows us to inline `format_nul_data` into this new
> structure. Let’s also rename `stdin_mode_arg` to `stdin_mode`.
> (We couldn’t use `stdin_mode` before because of the enumeration
> with the same name.)
>
> Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
> ---
> builtin/name-rev.c | 44 +++++++++++++++++++++++---------------------
> 1 file changed, 23 insertions(+), 21 deletions(-)
>
> diff --git a/builtin/name-rev.c b/builtin/name-rev.c
> index 254c88199fd..7d824aa1c5d 100644
> --- a/builtin/name-rev.c
> +++ b/builtin/name-rev.c
> @@ -772,16 +772,19 @@ int cmd_name_rev(int argc,
> return 0;
> }
>
> -struct format_nul_data {
> +struct format_rev_data {
> + const char *format;
> + const char *stdin_mode;
> bool nul_input;
> bool nul_output;
> + struct string_list notes;
> };
>
> static int format_nul_cb(const struct option *option,
> const char *arg,
> int unset)
> {
> - struct format_nul_data *data = option->value;
> + struct format_rev_data *data = option->value;
> data->nul_input = 1;
> data->nul_output = 1;
> BUG_ON_OPT_NEG(unset);
> @@ -813,31 +816,30 @@ int cmd_format_rev(int argc,
> const char *prefix,
> struct repository *repo UNUSED)
> {
> - const char *format = NULL;
> + struct format_rev_data data = {
> + NULL, NULL, 0, 0, STRING_LIST_INIT_NODUP
> + };
It will make it easier to maintain if you used designated
initializer here, i.e.,
struct format_rev_data data = {
.notes = STRING_LIST_INIT_NODUP,
};
The other members not explicitly mentioned by the initializer will
be zero-initialized.
Other parts of the patch look good.
Thanks.
next prev parent reply other threads:[~2026-08-13 18:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 17:23 [PATCH 0/4] format-rev: add --abbrev, --color, and --date kristofferhaugsbakk
2026-08-13 17:23 ` [PATCH 1/4] format-rev: use lower case for opts description kristofferhaugsbakk
2026-08-13 17:23 ` [PATCH 2/4] format-rev: factor option variables into a struct kristofferhaugsbakk
2026-08-13 18:21 ` Junio C Hamano [this message]
2026-08-13 17:23 ` [PATCH 3/4] doc: rev-list-options.adoc: factor out --date alts kristofferhaugsbakk
2026-08-13 17:24 ` [PATCH 4/4] format-rev: learn --abbrev, --color, and --date kristofferhaugsbakk
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=xmqqfr0hswxm.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=code@khaugsbakk.name \
--cc=git@vger.kernel.org \
--cc=kristofferhaugsbakk@fastmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.