git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/5] Improve message-id generation flow control for format-patch

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Feb 19, 2008, 03:56 UTC
Message-ID
<alpine.LNX.1.00.0802182254110.5816@iabervon.org>
In-Reply-To
<cover.1203392527.git.barkalow@iabervon.org>
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 builtin-log.c |   29 ++++++++++++++---------------
 revision.h    |    2 +-
 2 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 99d69f0..4f08ca4 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -575,16 +575,19 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const cha
 	o2->flags = flags2;
 }
 
-static void gen_message_id(char *dest, unsigned int length, char *base)
+static void gen_message_id(struct rev_info *info, char *base)
 {
 	const char *committer = git_committer_info(IDENT_WARN_ON_NO_NAME);
 	const char *email_start = strrchr(committer, '<');
 	const char *email_end = strrchr(committer, '>');
-	if(!email_start || !email_end || email_start > email_end - 1)
+	struct strbuf buf;
+	if (!email_start || !email_end || email_start > email_end - 1)
 		die("Could not extract email from committer identity.");
-	snprintf(dest, length, "%s.%lu.git.%.*s", base,
-		 (unsigned long) time(NULL),
-		 (int)(email_end - email_start - 1), email_start + 1);
+	strbuf_init(&buf, 0);
+	strbuf_addf(&buf, "%s.%lu.git.%.*s", base,
+		    (unsigned long) time(NULL),
+		    (int)(email_end - email_start - 1), email_start + 1);
+	info->message_id = strbuf_detach(&buf, NULL);
 }
 
 static const char *clean_message_id(const char *msg_id)
@@ -625,8 +628,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	const char *in_reply_to = NULL;
 	struct patch_ids ids;
 	char *add_signoff = NULL;
-	char message_id[1024];
-	char ref_message_id[1024];
 
 	git_config(git_format_config);
 	init_revisions(&rev, prefix);
@@ -809,15 +810,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		rev.nr = total - nr + (start_number - 1);
 		/* Make the second and subsequent mails replies to the first */
 		if (thread) {
-			if (nr == (total - 2)) {
-				strncpy(ref_message_id, message_id,
-					sizeof(ref_message_id));
-				ref_message_id[sizeof(ref_message_id)-1]='\0';
-				rev.ref_message_id = ref_message_id;
+			if (rev.message_id) {
+				if (rev.ref_message_id)
+					free(rev.message_id);
+				else
+					rev.ref_message_id = rev.message_id;
 			}
-			gen_message_id(message_id, sizeof(message_id),
-				       sha1_to_hex(commit->object.sha1));
-			rev.message_id = message_id;
+			gen_message_id(&rev, sha1_to_hex(commit->object.sha1));
 		}
 		if (!use_stdout)
 			if (reopen_stdout(commit, rev.nr, keep_subject,
diff --git a/revision.h b/revision.h
index 8572315..e3559d0 100644
--- a/revision.h
+++ b/revision.h
@@ -74,7 +74,7 @@ struct rev_info {
 	struct log_info *loginfo;
 	int		nr, total;
 	const char	*mime_boundary;
-	const char	*message_id;
+	char		*message_id;
 	const char	*ref_message_id;
 	const char	*add_signoff;
 	const char	*extra_headers;
-- 
1.5.4.1.191.gfbf10
Previous: Daniel BarkalowNext: Johannes Schindelin
Message 2 of 12 in “Add more tests for format-patch”
  1. 1/5 Add more tests for format-patchDaniel Barkalow, Feb 19, 2008
  2. 2/5 Improve message-id generation flow control for format-patchDaniel Barkalow, Feb 19, 2008
  3. Johannes SchindelinFeb 19, 2008
  4. Daniel BarkalowFeb 19, 2008
  5. Johannes SchindelinFeb 19, 2008
  6. 3/5 Export some email and pretty-printing functionsDaniel Barkalow, Feb 19, 2008
  7. Johannes SchindelinFeb 19, 2008
  8. Daniel BarkalowFeb 19, 2008
  9. 4/5 Retain extra blank lines between the summary and the bodyDaniel Barkalow, Feb 19, 2008
  10. 5/5 Add a --cover-letter option to format-patchDaniel Barkalow, Feb 19, 2008
  11. Junio C HamanoFeb 20, 2008
  12. Daniel BarkalowFeb 20, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.