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

[PATCH v2 next 2/4] format-patch: track several references

From
Thomas Rast <trast@student.ethz.ch>
Date
Feb 20, 2009, 19:55 UTC
Message-ID
<456d13c294a3154f8200cf44e0f80963f1e09d9e.1235158956.git.trast@student.ethz.ch>
In-Reply-To
<cover.1235158956.git.trast@student.ethz.ch>

Currently, format-patch can only track a single reference (the In-Reply-To:) for each mail. To ensure proper threading, we should list all known references for every mail.

Replace the rev_info.ref_message_id field by a string_list ref_message_ids, so that we can append references at will, and change the output formatting routines to print all of them in the References: header. The last entry in the list is implicitly assumed to be the In-Reply-To:, which gives output consistent with RFC 2822:

   The "References:" field will contain the contents of the parent's
   "References:" field (if any) followed by the contents of the
   parent's "Message-ID:" field (if any).

Note that this is just preparatory work; nothing uses it yet, so all "References:" fields in the output are still only one deep.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---

Changed 'ref_message_id' to 'ref_message_ids' as per Daniel's suggestion. Adjusted the commit message accordingly.

 builtin-log.c |   14 ++++++++++----
 log-tree.c    |   11 ++++++++---
 revision.h    |    2 +-
 3 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 8549028..1d7cf2f 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -17,6 +17,7 @@
 #include "run-command.h"
 #include "shortlog.h"
 #include "remote.h"
+#include "string-list.h"
 
 /* Set a default date-time format for git log ("log.date" config variable) */
 static const char *default_date_mode = NULL;
@@ -1030,8 +1031,12 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		numbered = 1;
 	if (numbered)
 		rev.total = total + start_number - 1;
-	if (in_reply_to)
-		rev.ref_message_id = clean_message_id(in_reply_to);
+	if (in_reply_to || thread || cover_letter)
+		rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
+	if (in_reply_to) {
+		const char *msgid = clean_message_id(in_reply_to);
+		string_list_append(msgid, rev.ref_message_ids);
+	}
 	if (cover_letter) {
 		if (thread)
 			gen_message_id(&rev, "cover");
@@ -1055,10 +1060,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 				 * otherwise, make everything a reply
 				 * to that.
 				 */
-				if (rev.ref_message_id)
+				if (rev.ref_message_ids->nr > 0)
 					free(rev.message_id);
 				else
-					rev.ref_message_id = rev.message_id;
+					string_list_append(rev.message_id,
+							   rev.ref_message_ids);
 			}
 			gen_message_id(&rev, sha1_to_hex(commit->object.sha1));
 		}
diff --git a/log-tree.c b/log-tree.c
index 84a74e5..a315ebb 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -6,6 +6,7 @@
 #include "log-tree.h"
 #include "reflog-walk.h"
 #include "refs.h"
+#include "string-list.h"
 
 struct decoration name_decoration = { "object names" };
 
@@ -211,9 +212,13 @@ void log_write_email_headers(struct rev_info *opt, const char *name,
 		printf("Message-Id: <%s>\n", opt->message_id);
 		graph_show_oneline(opt->graph);
 	}
-	if (opt->ref_message_id) {
-		printf("In-Reply-To: <%s>\nReferences: <%s>\n",
-		       opt->ref_message_id, opt->ref_message_id);
+	if (opt->ref_message_ids && opt->ref_message_ids->nr > 0) {
+		int i, n;
+		n = opt->ref_message_ids->nr;
+		printf("In-Reply-To: <%s>\n", opt->ref_message_ids->items[n-1].string);
+		for (i = 0; i < n; i++)
+			printf("%s<%s>\n", (i > 0 ? "\t" : "References: "),
+			       opt->ref_message_ids->items[i].string);
 		graph_show_oneline(opt->graph);
 	}
 	if (opt->mime_boundary) {
diff --git a/revision.h b/revision.h
index 7cf8487..8c0a417 100644
--- a/revision.h
+++ b/revision.h
@@ -89,7 +89,7 @@ struct rev_info {
 	int		nr, total;
 	const char	*mime_boundary;
 	char		*message_id;
-	const char	*ref_message_id;
+	struct string_list *ref_message_ids;
 	const char	*add_signoff;
 	const char	*extra_headers;
 	const char	*log_reencode;
-- 
1.6.2.rc1.310.ga3b4a
Previous: Thomas RastNext: Thomas Rast
Message 17 of 26 in “bash completion: offer more options for gitk”
  1. bash completion: offer more options for gitkThomas Rast, Feb 14, 2009
  2. Junio C HamanoFeb 15, 2009
  3. Santi BéjarFeb 15, 2009
  4. 0/2 bash completion: more options for gitk/log/shortlogThomas Rast, Feb 16, 2009
  5. Thomas RastFeb 16, 2009
  6. format-patch: thread as reply to cover letter even with in-reply-toThomas Rast, Feb 16, 2009
  7. Jay SoffianFeb 16, 2009
  8. Thomas RastFeb 16, 2009
  9. Jakub NarebskiFeb 16, 2009
  10. Thomas RastFeb 16, 2009
  11. 0/4 format-patch --cover-letter --in-reply-toThomas Rast, Feb 19, 2009
  12. 1/4 format-patch: threading test reactivationThomas Rast, Feb 19, 2009
  13. 2/4 format-patch: track several referencesThomas Rast, Feb 19, 2009
  14. Daniel BarkalowFeb 19, 2009
  15. 0/4 format-patch --cover-letter --in-reply-toThomas Rast, Feb 20, 2009
  16. 1/4 format-patch: threading test reactivationThomas Rast, Feb 20, 2009
  17. 2/4 format-patch: track several referencesThomas Rast, Feb 20, 2009
  18. 3/4 format-patch: thread as reply to cover letter even with in-reply-toThomas Rast, Feb 20, 2009
  19. 4/4 format-patch: support deep threadingThomas Rast, Feb 20, 2009
  20. Junio C HamanoFeb 22, 2009
  21. 3/4 format-patch: thread as reply to cover letter even with in-reply-toThomas Rast, Feb 19, 2009
  22. 4/4 format-patch: support deep threadingThomas Rast, Feb 19, 2009
  23. 1/2 bash completion: refactor common log, shortlog and gitk optionsThomas Rast, Feb 16, 2009
  24. 2/2 bash completion: only show 'log --merge' if mergingThomas Rast, Feb 16, 2009
  25. Shawn O. PearceFeb 18, 2009
  26. Junio C HamanoFeb 18, 2009

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.