public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Christian Couder <christian.couder@gmail•com>
To: git@vger•kernel.org
Cc: Junio C Hamano <gitster@pobox•com>,
	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 <christian.couder@gmail•com>,
	Christian Couder <chriscool@tuxfamily•org>
Subject: [PATCH v2 1/3] fast-import: refactor finalize_commit_buffer()
Date: Mon, 17 Nov 2025 05:34:48 +0100	[thread overview]
Message-ID: <20251117043450.322644-2-christian.couder@gmail.com> (raw)
In-Reply-To: <20251117043450.322644-1-christian.couder@gmail.com>

In a following commit we are going to finalize commit buffers with or
without signatures in order to check the signatures and possibly drop
them.

To do so easily and without duplication, let's refactor the current
code that finalizes commit buffers into a new finalize_commit_buffer()
function.

Signed-off-by: Christian Couder <chriscool@tuxfamily•org>
---
 builtin/fast-import.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 7c194e71cb..cb0d2f635e 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -2815,6 +2815,18 @@ static void import_one_signature(struct signature_data *sig_sha1,
 		die(_("parse_one_signature() returned unknown hash algo"));
 }
 
+static void finalize_commit_buffer(struct strbuf *new_data,
+				   struct signature_data *sig_sha1,
+				   struct signature_data *sig_sha256,
+				   struct strbuf *msg)
+{
+	add_gpgsig_to_commit(new_data, "gpgsig ", sig_sha1);
+	add_gpgsig_to_commit(new_data, "gpgsig-sha256 ", sig_sha256);
+
+	strbuf_addch(new_data, '\n');
+	strbuf_addbuf(new_data, msg);
+}
+
 static void parse_new_commit(const char *arg)
 {
 	static struct strbuf msg = STRBUF_INIT;
@@ -2950,11 +2962,8 @@ static void parse_new_commit(const char *arg)
 			"encoding %s\n",
 			encoding);
 
-	add_gpgsig_to_commit(&new_data, "gpgsig ", &sig_sha1);
-	add_gpgsig_to_commit(&new_data, "gpgsig-sha256 ", &sig_sha256);
+	finalize_commit_buffer(&new_data, &sig_sha1, &sig_sha256, &msg);
 
-	strbuf_addch(&new_data, '\n');
-	strbuf_addbuf(&new_data, &msg);
 	free(author);
 	free(committer);
 	free(encoding);
-- 
2.52.0.rc2.6.g1f299c9613


  reply	other threads:[~2025-11-17  4:35 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-05  6:19 [PATCH 0/3] fast-import: add 'strip-if-invalid' mode to --signed-commits=<mode> Christian Couder
2025-11-05  6:19 ` [PATCH 1/3] fast-import: refactor finalize_commit_buffer() Christian Couder
2025-11-05  6:19 ` [PATCH 2/3] commit: refactor verify_commit_buffer() Christian Couder
2025-11-05  6:19 ` [PATCH 3/3] fast-import: add 'strip-if-invalid' mode to --signed-commits=<mode> Christian Couder
2025-11-08 18:32   ` Junio C Hamano
2025-11-12  7:25     ` Christian Couder
2025-11-12 16:51       ` Junio C Hamano
2025-11-05 14:40 ` [PATCH 0/3] " Junio C Hamano
2025-11-08  0:34   ` Elijah Newren
2025-11-12  7:22     ` Christian Couder
2025-11-12  7:19   ` Christian Couder
2025-11-12 16:51     ` Junio C Hamano
2025-11-17  4:34 ` [PATCH v2 " Christian Couder
2025-11-17  4:34   ` Christian Couder [this message]
2025-11-17  4:34   ` [PATCH v2 2/3] commit: refactor verify_commit_buffer() Christian Couder
2025-11-17  4:34   ` [PATCH v2 3/3] fast-import: add 'strip-if-invalid' mode to --signed-commits=<mode> Christian Couder
2025-11-17 19:52   ` [PATCH v2 0/3] " Elijah Newren
2025-11-18 18:29     ` Christian Couder
2025-11-18 19:03       ` Junio C Hamano
2025-11-18 19:04       ` Elijah Newren

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=20251117043450.322644-2-christian.couder@gmail.com \
    --to=christian.couder@gmail$(echo .)com \
    --cc=Johannes.Schindelin@gmx$(echo .)de \
    --cc=chriscool@tuxfamily$(echo .)org \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    --cc=newren@gmail$(echo .)com \
    --cc=peff@peff$(echo .)net \
    --cc=ps@pks$(echo .)im \
    --cc=sandals@crustytoothpaste$(echo .)net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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