From: Junio C Hamano <gitster@pobox.com>
To: Christian Couder <christian.couder@gmail.com>
Cc: git@vger.kernel.org, Patrick Steinhardt <ps@pks.im>,
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 2/2] fast-import: add '--signed-commits=<mode>' option
Date: Wed, 10 Sep 2025 10:09:36 -0700 [thread overview]
Message-ID: <xmqqtt1as08f.fsf@gitster.g> (raw)
In-Reply-To: <20250910080839.2142651-3-christian.couder@gmail.com> (Christian Couder's message of "Wed, 10 Sep 2025 10:08:39 +0200")
Christian Couder <christian.couder@gmail.com> writes:
> diff --git a/builtin/fast-import.c b/builtin/fast-import.c
> @@ -2785,6 +2787,23 @@ static void store_signature(struct signature_data *stored_sig,
> }
> }
>
> +/* Process signatures (up to 2: one "sha1" and one "sha256") */
> +static void import_signature(struct signature_data *sig_sha1,
> + struct signature_data *sig_sha256,
> + const char *v)
> +{
> + struct signature_data sig = { NULL, NULL, STRBUF_INIT };
> +
> + parse_one_signature(&sig, v);
> +
> + if (!strcmp(sig.hash_algo, "sha1"))
> + store_signature(sig_sha1, &sig, "SHA-1");
> + else if (!strcmp(sig.hash_algo, "sha256"))
> + store_signature(sig_sha256, &sig, "SHA-256");
> + else
> + BUG("parse_one_signature() returned unknown hash algo");
> +}
> +
THis is a new function; I am not sure if the division of labor
between this one and its caller is done right. See below.
> @@ -2817,19 +2836,28 @@ static void parse_new_commit(const char *arg)
> if (!committer)
> die("Expected committer but didn't get one");
>
> - /* Process signatures (up to 2: one "sha1" and one "sha256") */
> while (skip_prefix(command_buf.buf, "gpgsig ", &v)) {
> - struct signature_data sig = { NULL, NULL, STRBUF_INIT };
> -
> - parse_one_signature(&sig, v);
> -
> - if (!strcmp(sig.hash_algo, "sha1"))
> - store_signature(&sig_sha1, &sig, "SHA-1");
> - else if (!strcmp(sig.hash_algo, "sha256"))
> - store_signature(&sig_sha256, &sig, "SHA-256");
> - else
> - BUG("parse_one_signature() returned unknown hash algo");
> -
> + struct strbuf data = STRBUF_INIT;
> + switch (signed_commit_mode) {
> + case SIGN_ABORT:
> + die("encountered signed commit; use "
> + "--signed-commits=<mode> to handle it");
> + case SIGN_WARN_VERBATIM:
> + warning("importing a commit signature");
> + /* fallthru */
> + case SIGN_VERBATIM:
> + import_signature(&sig_sha1, &sig_sha256, v);
> + break;
> + case SIGN_WARN_STRIP:
> + warning("stripping a commit signature");
> + /* fallthru */
> + case SIGN_STRIP:
> + /* Read signature data and discard it */
> + read_next_command();
> + parse_data(&data, 0, NULL);
> + strbuf_release(&data);
> + break;
> + }
> read_next_command();
> }
I am not sure if this change had to be this way. The old code
always called parse_one_signature(), which was responsible for
checking the signature format and then calling read_next_command()
and parse_data(), so no matter what happened afterwards, we know we
are consuming the data stream regardless of the conditional execution
that happens here.
The new code calls import_signature() or an inlined sequence of
read_next_command() plus parse_data(), essentially making each case
arm in the switch() statement responsible individually for consuming
the incoming data. When somebody adds a new case there to specify a
different way to handle signatures, they have to make sure that they
do not forget calling read_next_command() and parse_data() themselves.
Even though I can see, after some code inspection, that no branches
in the current code forgets to advance the incoming data stream to
leave us out of sync right now, this change feels like a bit of code
ergonomics regression to me. Was it so important that we pass a
broken signature without inspecting in STRIP mode? I am guessing
that is the reason why the new code tries hard to avoid calling the
parse_one_signature() function in these case arms.
An aside. I think the warning message about importing should have a
word "verbatim" in it, e.g.
warning("importing a commit signature verbatim");
Thanks.
next prev parent reply other threads:[~2025-09-10 17:09 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
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 [this message]
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=xmqqtt1as08f.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=chriscool@tuxfamily.org \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=ps@pks.im \
--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).