From: Patrick Steinhardt <ps@pks.im>
To: Christian Couder <christian.couder@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Elijah Newren <newren@gmail.com>, Jeff King <peff@peff.net>,
"brian m . carlson" <sandals@crustytoothpaste.net>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Christian Couder <chriscool@tuxfamily.org>
Subject: Re: [PATCH 1/2] gpg-interface: refactor 'enum sign_mode' parsing
Date: Thu, 11 Sep 2025 08:06:31 +0200 [thread overview]
Message-ID: <aMJm57VmWb3h167z@pks.im> (raw)
In-Reply-To: <20250910080839.2142651-2-christian.couder@gmail.com>
On Wed, Sep 10, 2025 at 10:08:38AM +0200, Christian Couder wrote:
> diff --git a/builtin/fast-export.c b/builtin/fast-export.c
> index c06ee0b213..3994a8f898 100644
> --- a/builtin/fast-export.c
> +++ b/builtin/fast-export.c
> @@ -59,24 +57,17 @@ static struct hashmap anonymized_seeds;
> static struct revision_sources revision_sources;
>
> static int parse_opt_sign_mode(const struct option *opt,
> - const char *arg, int unset)
> + const char *arg, int unset)
> {
> enum sign_mode *val = opt->value;
> +
> if (unset)
> return 0;
> - else if (!strcmp(arg, "abort"))
> - *val = SIGN_ABORT;
> - else if (!strcmp(arg, "verbatim") || !strcmp(arg, "ignore"))
> - *val = SIGN_VERBATIM;
> - else if (!strcmp(arg, "warn-verbatim") || !strcmp(arg, "warn"))
> - *val = SIGN_WARN_VERBATIM;
> - else if (!strcmp(arg, "warn-strip"))
> - *val = SIGN_WARN_STRIP;
> - else if (!strcmp(arg, "strip"))
> - *val = SIGN_STRIP;
> - else
> - return error("Unknown %s mode: %s", opt->long_name, arg);
> - return 0;
> +
> + if (!parse_sign_mode(arg, val))
> + return 0;
> +
> + return error("Unknown %s mode: %s", opt->long_name, arg);
Would it make sense to maybe reverse the error handling and say
something like:
if (parse_sign_mode(arg, val) < 0)
return error("Unknown %s mode: %s", opt->long_name, arg);
return 0;
That reads a bit more natural to me at least.
> diff --git a/gpg-interface.h b/gpg-interface.h
> index 60ddf8bbfa..44856cc55f 100644
> --- a/gpg-interface.h
> +++ b/gpg-interface.h
> @@ -104,4 +104,19 @@ int check_signature(struct signature_check *sigc,
> void print_signature_buffer(const struct signature_check *sigc,
> unsigned flags);
>
> +/* Modes for --signed-tags=<mode> and --signed-commits=<mode> options */
Nit: let's finish this sentence with a dot.
> +enum sign_mode {
> + SIGN_ABORT,
> + SIGN_WARN_VERBATIM,
> + SIGN_VERBATIM,
> + SIGN_WARN_STRIP,
> + SIGN_STRIP,
> +};
> +
> +/*
> + * Return 0 if `arg` can be parsed into an `enum sign_mode`. Return -1
> + * otherwise.
> + */
> +int parse_sign_mode(const char *arg, enum sign_mode *mode);
Okay, makes sense.
Patrick
next prev parent reply other threads:[~2025-09-11 6:06 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-10 8:08 [PATCH 0/2] fast-import: start controlling how commit signatures are handled Christian Couder
2025-09-10 8:08 ` [PATCH 1/2] gpg-interface: refactor 'enum sign_mode' parsing Christian Couder
2025-09-10 16:50 ` Junio C Hamano
2025-09-11 6:06 ` Patrick Steinhardt [this message]
2025-09-11 16:29 ` Junio C Hamano
2025-09-12 12:40 ` Christian Couder
2025-09-12 12:40 ` Christian Couder
2025-09-10 8:08 ` [PATCH 2/2] fast-import: add '--signed-commits=<mode>' option Christian Couder
2025-09-10 17:09 ` Junio C Hamano
2025-09-12 13:35 ` Christian Couder
2025-09-12 14:14 ` Junio C Hamano
2025-09-15 10:29 ` Christian Couder
2025-09-15 16:02 ` Junio C Hamano
2025-09-17 18:27 ` Christian Couder
2025-09-10 18:21 ` Junio C Hamano
2025-09-12 13:41 ` Christian Couder
2025-09-12 14:09 ` Junio C Hamano
2025-09-11 6:06 ` Patrick Steinhardt
2025-09-11 16:55 ` Junio C Hamano
2025-09-12 13:47 ` Christian Couder
2025-09-12 13:25 ` Christian Couder
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=aMJm57VmWb3h167z@pks.im \
--to=ps@pks.im \
--cc=Johannes.Schindelin@gmx.de \
--cc=chriscool@tuxfamily.org \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=sandals@crustytoothpaste.net \
/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;
as well as URLs for NNTP newsgroup(s).