Skip to content

Commit d1566f7

Browse files
Josh TriplettJunio C Hamano
Josh Triplett
authored and
Junio C Hamano
committed
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a3e65d7 commit d1566f7

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

builtin-log.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,17 @@ static void get_patch_ids(struct rev_info *rev, struct diff_options *options)
226226
o2->flags = flags2;
227227
}
228228

229+
static void gen_message_id(char *dest, unsigned int length, char *base)
230+
{
231+
const char *committer = git_committer_info(1);
232+
const char *email_start = strrchr(committer, '<');
233+
const char *email_end = strrchr(committer, '>');
234+
if(!email_start || !email_end || email_start > email_end - 1)
235+
die("Could not extract email from committer identity.");
236+
snprintf(dest, length, "%s.%u.git.%.*s", base, time(NULL),
237+
email_end - email_start - 1, email_start + 1);
238+
}
239+
229240
int cmd_format_patch(int argc, const char **argv, char **envp)
230241
{
231242
struct commit *commit;
@@ -239,6 +250,8 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
239250
int ignore_if_in_upstream = 0;
240251
struct diff_options patch_id_opts;
241252
char *add_signoff = NULL;
253+
char message_id[1024];
254+
char ref_message_id[1024];
242255

243256
git_config(git_format_config);
244257
init_revisions(&rev);
@@ -365,6 +378,16 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
365378
int shown;
366379
commit = list[nr];
367380
rev.nr = total - nr + (start_number - 1);
381+
/* Make the second and subsequent mails replies to the first */
382+
if (nr == (total - 2)) {
383+
strncpy(ref_message_id, message_id,
384+
sizeof(ref_message_id));
385+
ref_message_id[sizeof(ref_message_id)-1] = '\0';
386+
rev.ref_message_id = ref_message_id;
387+
}
388+
gen_message_id(message_id, sizeof(message_id),
389+
sha1_to_hex(commit->object.sha1));
390+
rev.message_id = message_id;
368391
if (!use_stdout)
369392
reopen_stdout(commit, rev.nr, keep_subject);
370393
shown = log_tree_commit(&rev, commit);

log-tree.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ void show_log(struct rev_info *opt, const char *sep)
9797
subject = "Subject: ";
9898

9999
printf("From %s Mon Sep 17 00:00:00 2001\n", sha1);
100+
if (opt->message_id)
101+
printf("Message-Id: <%s>\n", opt->message_id);
102+
if (opt->ref_message_id)
103+
printf("In-Reply-To: <%s>\nReferences: <%s>\n",
104+
opt->ref_message_id, opt->ref_message_id);
100105
if (opt->mime_boundary) {
101106
static char subject_buffer[1024];
102107
static char buffer[1024];

revision.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ struct rev_info {
6161
struct log_info *loginfo;
6262
int nr, total;
6363
const char *mime_boundary;
64+
const char *message_id;
65+
const char *ref_message_id;
6466
const char *add_signoff;
6567
const char *extra_headers;
6668

0 commit comments

Comments
 (0)