threads / patch / 4889

patchAdd option to set initial In-Reply-To/References

Subject: [PATCH] Add option to set initial In-Reply-To/References

## tl;dr

2 messages between Jul 15, 2006 and Jul 15, 2006. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Josh Triplett· Jul 15, 2006, 00:49 UTC · lore

[PATCH] 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 <josh@freedesktop.org>
---
 Documentation/git-format-patch.txt |   10 +++++++++-
 builtin-log.c                      |   21 +++++++++++++--------
 2 files changed, 22 insertions(+), 9 deletions(-)
Show changes to 2 files +22 −9

Documentation/git-format-patch.txt, builtin-log.c

diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt
index 4ca0014..305bd79 100644
--- a/Documentation/git-format-patch.txt
+++ b/Documentation/git-format-patch.txt
@@ -9,7 +9,7 @@ git-format-patch - Prepare patches for e
 SYNOPSIS
 --------
 [verse]
-'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--attach]
+'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--attach] [--thread]
 	           [-s | --signoff] [--diff-options] [--start-number <n>]
 		   <since>[..<until>]
 
@@ -35,6 +35,10 @@ they are created in the current working 
 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 9d0cae1..4572295 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -242,6 +242,7 @@ int cmd_format_patch(int argc, const cha
 	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];
@@ -311,6 +312,8 @@ int cmd_format_patch(int argc, const cha
 			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];
 	}
@@ -373,15 +376,17 @@ int cmd_format_patch(int argc, const cha
 		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);
-- 
1.4.1.gd2cb0
Josh Triplett· Jul 15, 2006, 00:49 UTC · lore

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 <josh@freedesktop.org>
---
 Documentation/git-format-patch.txt |    6 ++++++
 builtin-log.c                      |   10 ++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)
Show changes to 2 files +16 −0

Documentation/git-format-patch.txt, builtin-log.c

diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt
index 305bd79..67425dc 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 <dir> | --stdout] [--attach] [--thread]
 	           [-s | --signoff] [--diff-options] [--start-number <n>]
+		   [--in-reply-to=Message-Id]
 		   <since>[..<until>]
 
 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 4572295..3ef7b8e 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -243,6 +243,7 @@ int cmd_format_patch(int argc, const cha
 	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];
@@ -314,6 +315,14 @@ int cmd_format_patch(int argc, const cha
 			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];
 	}
@@ -371,6 +380,7 @@ int cmd_format_patch(int argc, const cha
 	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];
-- 
1.4.1.gd2cb0

← back to recent threads