From d1566f7883f727f38bf442af3fdb69d36e6fcea2 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 14 Jul 2006 17:48:51 -0700 Subject: [PATCH 1/4] git-format-patch: Make the second and subsequent mails replies to the first Add message_id and ref_message_id fields to struct rev_info, used in show_log with CMIT_FMT_EMAIL to set Message-Id and In-Reply-To/References respectively. Use these in git-format-patch to make the second and subsequent patch mails replies to the first patch mail. Signed-off-by: Josh Triplett Signed-off-by: Junio C Hamano --- builtin-log.c | 23 +++++++++++++++++++++++ log-tree.c | 5 +++++ revision.h | 2 ++ 3 files changed, 30 insertions(+) diff --git a/builtin-log.c b/builtin-log.c index 7e5cab15c1..1f1074cec6 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -226,6 +226,17 @@ static void get_patch_ids(struct rev_info *rev, struct diff_options *options) o2->flags = flags2; } +static void gen_message_id(char *dest, unsigned int length, char *base) +{ + const char *committer = git_committer_info(1); + const char *email_start = strrchr(committer, '<'); + const char *email_end = strrchr(committer, '>'); + if(!email_start || !email_end || email_start > email_end - 1) + die("Could not extract email from committer identity."); + snprintf(dest, length, "%s.%u.git.%.*s", base, time(NULL), + email_end - email_start - 1, email_start + 1); +} + int cmd_format_patch(int argc, const char **argv, char **envp) { struct commit *commit; @@ -239,6 +250,8 @@ int cmd_format_patch(int argc, const char **argv, char **envp) int ignore_if_in_upstream = 0; struct diff_options patch_id_opts; char *add_signoff = NULL; + char message_id[1024]; + char ref_message_id[1024]; git_config(git_format_config); init_revisions(&rev); @@ -365,6 +378,16 @@ int cmd_format_patch(int argc, const char **argv, char **envp) int shown; commit = list[nr]; rev.nr = total - nr + (start_number - 1); + /* Make the second and subsequent mails replies to the first */ + 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; + } + gen_message_id(message_id, sizeof(message_id), + sha1_to_hex(commit->object.sha1)); + rev.message_id = message_id; if (!use_stdout) reopen_stdout(commit, rev.nr, keep_subject); shown = log_tree_commit(&rev, commit); diff --git a/log-tree.c b/log-tree.c index 9d8d46fa00..4971988417 100644 --- a/log-tree.c +++ b/log-tree.c @@ -97,6 +97,11 @@ void show_log(struct rev_info *opt, const char *sep) subject = "Subject: "; printf("From %s Mon Sep 17 00:00:00 2001\n", sha1); + if (opt->message_id) + printf("Message-Id: <%s>\n", opt->message_id); + if (opt->ref_message_id) + printf("In-Reply-To: <%s>\nReferences: <%s>\n", + opt->ref_message_id, opt->ref_message_id); if (opt->mime_boundary) { static char subject_buffer[1024]; static char buffer[1024]; diff --git a/revision.h b/revision.h index c010a08116..e23ec8f45a 100644 --- a/revision.h +++ b/revision.h @@ -61,6 +61,8 @@ struct rev_info { struct log_info *loginfo; int nr, total; const char *mime_boundary; + const char *message_id; + const char *ref_message_id; const char *add_signoff; const char *extra_headers; From cc35de8470541e389b7d2bdda4c901574720fa81 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 14 Jul 2006 17:49:04 -0700 Subject: [PATCH 2/4] Add option to enable threading headers Add a --thread option to enable generation of In-Reply-To and References headers, used to make the second and subsequent mails appear as replies to the first. Signed-off-by: Josh Triplett Signed-off-by: Junio C Hamano --- Documentation/git-format-patch.txt | 10 +++++++++- builtin-log.c | 21 +++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 4ca0014dac..305bd79154 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -9,7 +9,7 @@ git-format-patch - Prepare patches for e-mail submission SYNOPSIS -------- [verse] -'git-format-patch' [-n | -k] [-o | --stdout] [--attach] +'git-format-patch' [-n | -k] [-o | --stdout] [--attach] [--thread] [-s | --signoff] [--diff-options] [--start-number ] [..] @@ -35,6 +35,10 @@ they are created in the current working directory. If -n is specified, instead of "[PATCH] Subject", the first line is formatted as "[PATCH n/m] Subject". +If given --thread, git-format-patch will generate In-Reply-To and +References headers to make the second and subsequent patch mails appear +as replies to the first mail; this also generates a Message-Id header to +reference. OPTIONS ------- @@ -63,6 +67,10 @@ OPTIONS --attach:: Create attachments instead of inlining patches. +--thread:: + Add In-Reply-To and References headers to make the second and + subsequent mails appear as replies to the first. Also generates + the Message-Id header to reference. CONFIGURATION ------------- diff --git a/builtin-log.c b/builtin-log.c index 1f1074cec6..6466768051 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -248,6 +248,7 @@ int cmd_format_patch(int argc, const char **argv, char **envp) int start_number = -1; int keep_subject = 0; int ignore_if_in_upstream = 0; + int thread = 0; struct diff_options patch_id_opts; char *add_signoff = NULL; char message_id[1024]; @@ -317,6 +318,8 @@ int cmd_format_patch(int argc, const char **argv, char **envp) rev.mime_boundary = argv[i] + 9; else if (!strcmp(argv[i], "--ignore-if-in-upstream")) ignore_if_in_upstream = 1; + else if (!strcmp(argv[i], "--thread")) + thread = 1; else argv[j++] = argv[i]; } @@ -379,15 +382,17 @@ int cmd_format_patch(int argc, const char **argv, char **envp) commit = list[nr]; rev.nr = total - nr + (start_number - 1); /* Make the second and subsequent mails replies to the first */ - 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 (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; + } + gen_message_id(message_id, sizeof(message_id), + sha1_to_hex(commit->object.sha1)); + rev.message_id = message_id; } - gen_message_id(message_id, sizeof(message_id), - sha1_to_hex(commit->object.sha1)); - rev.message_id = message_id; if (!use_stdout) reopen_stdout(commit, rev.nr, keep_subject); shown = log_tree_commit(&rev, commit); From da56645dd7c1175fc2ed1628ac35fdd35e705641 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 14 Jul 2006 17:49:08 -0700 Subject: [PATCH 3/4] Add option to set initial In-Reply-To/References Add the --in-reply-to option to provide a Message-Id for an initial In-Reply-To/References header, useful for including a new patch series as part of an existing thread. Signed-off-by: Josh Triplett Signed-off-by: Junio C Hamano --- Documentation/git-format-patch.txt | 6 ++++++ builtin-log.c | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 305bd79154..67425dc035 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -11,6 +11,7 @@ SYNOPSIS [verse] 'git-format-patch' [-n | -k] [-o | --stdout] [--attach] [--thread] [-s | --signoff] [--diff-options] [--start-number ] + [--in-reply-to=Message-Id] [..] DESCRIPTION @@ -72,6 +73,11 @@ OPTIONS subsequent mails appear as replies to the first. Also generates the Message-Id header to reference. +--in-reply-to=Message-Id:: + Make the first mail (or all the mails with --no-thread) appear as a + reply to the given Message-Id, which avoids breaking threads to + provide a new patch series. + CONFIGURATION ------------- You can specify extra mail header lines to be added to each diff --git a/builtin-log.c b/builtin-log.c index 6466768051..705205331e 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -249,6 +249,7 @@ int cmd_format_patch(int argc, const char **argv, char **envp) int keep_subject = 0; int ignore_if_in_upstream = 0; int thread = 0; + char *in_reply_to = NULL; struct diff_options patch_id_opts; char *add_signoff = NULL; char message_id[1024]; @@ -320,6 +321,14 @@ int cmd_format_patch(int argc, const char **argv, char **envp) ignore_if_in_upstream = 1; else if (!strcmp(argv[i], "--thread")) thread = 1; + else if (!strncmp(argv[i], "--in-reply-to=", 14)) + in_reply_to = argv[i] + 14; + else if (!strcmp(argv[i], "--in-reply-to")) { + i++; + if (i == argc) + die("Need a Message-Id for --in-reply-to"); + in_reply_to = argv[i]; + } else argv[j++] = argv[i]; } @@ -377,6 +386,7 @@ int cmd_format_patch(int argc, const char **argv, char **envp) if (numbered) rev.total = total + start_number - 1; rev.add_signoff = add_signoff; + rev.ref_message_id = in_reply_to; while (0 <= --nr) { int shown; commit = list[nr]; From 76af073457320ffcba937a8c7ed4e8b37150cca8 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Jul 2006 22:47:53 -0700 Subject: [PATCH 4/4] builtin-log: typefix for recent format-patch changes. Signed-off-by: Junio C Hamano --- builtin-log.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/builtin-log.c b/builtin-log.c index 705205331e..4052cc75bd 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -10,6 +10,8 @@ #include "revision.h" #include "log-tree.h" #include "builtin.h" +#include +#include /* this is in builtin-diff.c */ void add_head(struct rev_info *revs); @@ -233,8 +235,9 @@ static void gen_message_id(char *dest, unsigned int length, char *base) const char *email_end = strrchr(committer, '>'); if(!email_start || !email_end || email_start > email_end - 1) die("Could not extract email from committer identity."); - snprintf(dest, length, "%s.%u.git.%.*s", base, time(NULL), - email_end - email_start - 1, email_start + 1); + snprintf(dest, length, "%s.%lu.git.%.*s", base, + (unsigned long) time(NULL), + (int)(email_end - email_start - 1), email_start + 1); } int cmd_format_patch(int argc, const char **argv, char **envp) @@ -249,7 +252,7 @@ int cmd_format_patch(int argc, const char **argv, char **envp) int keep_subject = 0; int ignore_if_in_upstream = 0; int thread = 0; - char *in_reply_to = NULL; + const char *in_reply_to = NULL; struct diff_options patch_id_opts; char *add_signoff = NULL; char message_id[1024];