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

[RFC/PATCH 1/1] format-patch: add an option to record base tree info

From
Xiaolong Ye <xiaolong.ye@intel.com>
Date
Feb 22, 2016, 02:58 UTC
Message-ID
<1456109938-8568-2-git-send-email-xiaolong.ye@intel.com>
In-Reply-To
<1456109938-8568-1-git-send-email-xiaolong.ye@intel.com>

It would be helpful for maintainers or reviewers to know the base tree info of the patches created by git format-patch. Teach git format-patch a --base-tree-info option to record these info.

Signed-off-by: Xiaolong Ye <xiaolong.ye@intel.com>
---
 builtin/log.c | 18 ++++++++++++++++++
 diff.c        |  4 ++++
 diff.h        |  3 ++-
 revision.h    |  1 +
 4 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/builtin/log.c b/builtin/log.c
index 0d738d6..bec7aee 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1189,6 +1189,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 {
 	struct commit *commit;
 	struct commit **list = NULL;
+	struct commit_list *parents = NULL;
 	struct rev_info rev;
 	struct setup_revision_opt s_r_opt;
 	int nr = 0, total, i;
@@ -1200,6 +1201,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	int boundary_count = 0;
 	int no_binary_diff = 0;
 	int zero_commit = 0;
+	int base_tree_info = 0;
 	struct commit *origin = NULL;
 	const char *in_reply_to = NULL;
 	struct patch_ids ids;
@@ -1242,6 +1244,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 			 N_("don't output binary diffs")),
 		OPT_BOOL(0, "zero-commit", &zero_commit,
 			 N_("output all-zero hash in From header")),
+		OPT_BOOL(0, "base-tree-info", &base_tree_info,
+			 N_("Add base tree info")),
 		OPT_BOOL(0, "ignore-if-in-upstream", &ignore_if_in_upstream,
 			 N_("don't include a patch matching a commit upstream")),
 		{ OPTION_SET_INT, 'p', "no-stat", &use_patch_format, NULL,
@@ -1387,6 +1391,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
 
 	rev.zero_commit = zero_commit;
+	rev.base_tree_info = base_tree_info;
 
 	if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)
 		DIFF_OPT_SET(&rev.diffopt, BINARY);
@@ -1484,6 +1489,12 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		/* nothing to do */
 		return 0;
 	total = nr;
+	parents = get_saved_parents(&rev, list[nr-1]);
+	if (rev.base_tree_info && parents) {
+		struct commit *base_commit = parents->item;
+		sha1_to_hex_r(rev.diffopt.base_commit_id, base_commit->object.oid.hash);
+	}
+
 	if (!keep_subject && auto_number && total > 1)
 		numbered = 1;
 	if (numbered)
@@ -1516,6 +1527,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	rev.numbered_files = just_numbers;
 	rev.patch_suffix = fmt_patch_suffix;
 	if (cover_letter) {
+		if (rev.base_tree_info)
+			DIFF_OPT_SET(&rev.diffopt, BASE_TREE_INFO);
 		if (thread)
 			gen_message_id(&rev, "cover");
 		make_cover_letter(&rev, use_stdout,
@@ -1528,6 +1541,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		int shown;
 		commit = list[nr];
 		rev.nr = total - nr + (start_number - 1);
+		if (!cover_letter && rev.nr == 1 && rev.base_tree_info)
+			DIFF_OPT_SET(&rev.diffopt, BASE_TREE_INFO);
+		else
+			DIFF_OPT_CLR(&rev.diffopt, BASE_TREE_INFO);
+
 		/* Make the second and subsequent mails replies to the first */
 		if (thread) {
 			/* Have we already had a message ID? */
diff --git a/diff.c b/diff.c
index 2136b69..a23d5a5 100644
--- a/diff.c
+++ b/diff.c
@@ -4650,6 +4650,7 @@ void diff_flush(struct diff_options *options)
 		separator++;
 	}
 
+
 	if (output_format & DIFF_FORMAT_NO_OUTPUT &&
 	    DIFF_OPT_TST(options, EXIT_WITH_STATUS) &&
 	    DIFF_OPT_TST(options, DIFF_FROM_CONTENTS)) {
@@ -4673,6 +4674,9 @@ void diff_flush(struct diff_options *options)
 		}
 	}
 
+	if (DIFF_OPT_TST(options, BASE_TREE_INFO))
+		fprintf(options->file, "\nbase commit: %s\n", options->base_commit_id);
+
 	if (output_format & DIFF_FORMAT_PATCH) {
 		if (separator) {
 			fprintf(options->file, "%s%c",
diff --git a/diff.h b/diff.h
index 70b2d70..0e62f63 100644
--- a/diff.h
+++ b/diff.h
@@ -69,7 +69,7 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
 #define DIFF_OPT_FIND_COPIES_HARDER  (1 <<  6)
 #define DIFF_OPT_FOLLOW_RENAMES      (1 <<  7)
 #define DIFF_OPT_RENAME_EMPTY        (1 <<  8)
-/* (1 <<  9) unused */
+#define DIFF_OPT_BASE_TREE_INFO      (1 <<  9)
 #define DIFF_OPT_HAS_CHANGES         (1 << 10)
 #define DIFF_OPT_QUICK               (1 << 11)
 #define DIFF_OPT_NO_INDEX            (1 << 12)
@@ -176,6 +176,7 @@ struct diff_options {
 	diff_prefix_fn_t output_prefix;
 	int output_prefix_length;
 	void *output_prefix_data;
+	char base_commit_id[GIT_SHA1_HEXSZ + 1];
 
 	int diff_path_counter;
 };
diff --git a/revision.h b/revision.h
index 23857c0..28c259b 100644
--- a/revision.h
+++ b/revision.h
@@ -136,6 +136,7 @@ struct rev_info {
 			abbrev_commit:1,
 			abbrev_commit_given:1,
 			zero_commit:1,
+			base_tree_info:1,
 			use_terminator:1,
 			missing_newline:1,
 			date_mode_explicit:1,
-- 
2.7.1.340.gf1cebb4
Previous: Xiaolong YeNext: Junio C Hamano
Message 2 of 29 in “Add an option to git-format-patch to record base tree info”
  1. 0/1 Add an option to git-format-patch to record base tree infoXiaolong Ye, Feb 22, 2016
  2. 1/1 format-patch: add an option to record base tree infoXiaolong Ye, Feb 22, 2016
  3. Junio C HamanoFeb 22, 2016
  4. Jacob KellerFeb 22, 2016
  5. Fengguang WuFeb 23, 2016
  6. Junio C HamanoFeb 23, 2016
  7. Fengguang WuFeb 23, 2016
  8. H. Peter AnvinFeb 23, 2016
  9. Fengguang WuFeb 23, 2016
  10. Dan CarpenterFeb 23, 2016
  11. Fengguang WuFeb 23, 2016
  12. Dan CarpenterFeb 23, 2016
  13. Fengguang WuFeb 24, 2016
  14. Junio C HamanoFeb 24, 2016
  15. Fengguang WuFeb 24, 2016
  16. Junio C HamanoFeb 24, 2016
  17. Junio C HamanoFeb 23, 2016
  18. Eric W. BiedermanFeb 23, 2016
  19. Junio C HamanoFeb 23, 2016
  20. H. Peter AnvinFeb 23, 2016
  21. Eric W. BiedermanFeb 23, 2016
  22. H. Peter AnvinFeb 24, 2016
  23. Stefan BellerFeb 23, 2016
  24. Michael J GruberFeb 24, 2016
  25. Junio C HamanoFeb 24, 2016
  26. Fengguang WuFeb 24, 2016
  27. Fengguang WuFeb 24, 2016
  28. Eric W. BiedermanFeb 23, 2016
  29. Fengguang WuFeb 24, 2016

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.