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@xxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html