{"thread":{"id":"4888","subject":"[PATCH] git-format-patch: Make the second and subsequent mails replies to the first","startedAt":"2006-07-15T00:48:51Z","lastAt":"2006-07-15T00:48:51Z","messageCount":1,"participants":["Josh Triplett"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"23847","messageId":"1152924531.3148.0.camel@josh-work.beaverton.ibm.com","threadId":"4888","inReplyTo":null,"subject":"[PATCH] git-format-patch: Make the second and subsequent mails replies to the first","fromName":"Josh Triplett","fromEmail":"josht@us.ibm.com","sentAt":"2006-07-15T00:48:51Z","receivedAt":"2006-07-15T00:48:51Z","isPatch":true,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"Add message_id and ref_message_id fields to struct rev_info, used in show_log\nwith CMIT_FMT_EMAIL to set Message-Id and In-Reply-To/References respectively.\nUse these in git-format-patch to make the second and subsequent patch mails\nreplies to the first patch mail.\n\nSigned-off-by: Josh Triplett <josh@freedesktop.org>\n---\n builtin-log.c |   23 +++++++++++++++++++++++\n log-tree.c    |    5 +++++\n revision.h    |    2 ++\n 3 files changed, 30 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 864c6cd..9d0cae1 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -220,6 +220,17 @@ static void get_patch_ids(struct rev_inf\n \to2->flags = flags2;\n }\n \n+static void gen_message_id(char *dest, unsigned int length, char *base)\n+{\n+\tconst char *committer = git_committer_info(1);\n+\tconst char *email_start = strrchr(committer, '<');\n+\tconst char *email_end = strrchr(committer, '>');\n+\tif(!email_start || !email_end || email_start > email_end - 1)\n+\t\tdie(\"Could not extract email from committer identity.\");\n+\tsnprintf(dest, length, \"%s.%u.git.%.*s\", base, time(NULL),\n+\t\t email_end - email_start - 1, email_start + 1);\n+}\n+\n int cmd_format_patch(int argc, const char **argv, char **envp)\n {\n \tstruct commit *commit;\n@@ -233,6 +244,8 @@ int cmd_format_patch(int argc, const cha\n \tint ignore_if_in_upstream = 0;\n \tstruct diff_options patch_id_opts;\n \tchar *add_signoff = NULL;\n+\tchar message_id[1024];\n+\tchar ref_message_id[1024];\n \n \tinit_revisions(&rev);\n \trev.commit_format = CMIT_FMT_EMAIL;\n@@ -359,6 +372,16 @@ int cmd_format_patch(int argc, const cha\n \t\tint shown;\n \t\tcommit = list[nr];\n \t\trev.nr = total - nr + (start_number - 1);\n+\t\t/* Make the second and subsequent mails replies to the first */\n+\t\tif (nr == (total - 2)) {\n+\t\t\tstrncpy(ref_message_id, message_id,\n+\t\t\t\tsizeof(ref_message_id));\n+\t\t\tref_message_id[sizeof(ref_message_id)-1] = '\\0';\n+\t\t\trev.ref_message_id = ref_message_id;\n+\t\t}\n+\t\tgen_message_id(message_id, sizeof(message_id),\n+\t\t\t       sha1_to_hex(commit->object.sha1));\n+\t\trev.message_id = message_id;\n \t\tif (!use_stdout)\n \t\t\treopen_stdout(commit, rev.nr, keep_subject);\n \t\tshown = log_tree_commit(&rev, commit);\ndiff --git a/log-tree.c b/log-tree.c\nindex 9d8d46f..4971988 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -97,6 +97,11 @@ void show_log(struct rev_info *opt, cons\n \t\t\tsubject = \"Subject: \";\n \n \t\tprintf(\"From %s Mon Sep 17 00:00:00 2001\\n\", sha1);\n+\t\tif (opt->message_id)\n+\t\t\tprintf(\"Message-Id: <%s>\\n\", opt->message_id);\n+\t\tif (opt->ref_message_id)\n+\t\t\tprintf(\"In-Reply-To: <%s>\\nReferences: <%s>\\n\",\n+\t\t\t       opt->ref_message_id, opt->ref_message_id);\n \t\tif (opt->mime_boundary) {\n \t\t\tstatic char subject_buffer[1024];\n \t\t\tstatic char buffer[1024];\ndiff --git a/revision.h b/revision.h\nindex c010a08..e23ec8f 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -61,6 +61,8 @@ struct rev_info {\n \tstruct log_info *loginfo;\n \tint\t\tnr, total;\n \tconst char\t*mime_boundary;\n+\tconst char\t*message_id;\n+\tconst char\t*ref_message_id;\n \tconst char\t*add_signoff;\n \tconst char\t*extra_headers;\n \n-- \n1.4.1.gd2cb0\n"}]}