Skip to content

Commit fa5b7ea

Browse files
sunshinecogitster
authored andcommitted
format-patch: allow additional generated content in make_cover_letter()
make_cover_letter() returns early when it lacks sufficient state to emit a diffstat, which makes it difficult to extend the function to reliably emit additional generated content. Work around this shortcoming by factoring diffstat-printing logic out to its own function and calling it as needed without otherwise inhibiting normal control flow. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b7bd948 commit fa5b7ea

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

builtin/log.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,26 @@ static char *find_branch_name(struct rev_info *rev)
997997
return branch;
998998
}
999999

1000+
static void show_diffstat(struct rev_info *rev,
1001+
struct commit *origin, struct commit *head)
1002+
{
1003+
struct diff_options opts;
1004+
1005+
memcpy(&opts, &rev->diffopt, sizeof(opts));
1006+
opts.output_format = DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
1007+
opts.stat_width = MAIL_DEFAULT_WRAP;
1008+
1009+
diff_setup_done(&opts);
1010+
1011+
diff_tree_oid(get_commit_tree_oid(origin),
1012+
get_commit_tree_oid(head),
1013+
"", &opts);
1014+
diffcore_std(&opts);
1015+
diff_flush(&opts);
1016+
1017+
fprintf(rev->diffopt.file, "\n");
1018+
}
1019+
10001020
static void make_cover_letter(struct rev_info *rev, int use_stdout,
10011021
struct commit *origin,
10021022
int nr, struct commit **list,
@@ -1010,7 +1030,6 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
10101030
struct strbuf sb = STRBUF_INIT;
10111031
int i;
10121032
const char *encoding = "UTF-8";
1013-
struct diff_options opts;
10141033
int need_8bit_cte = 0;
10151034
struct pretty_print_context pp = {0};
10161035
struct commit *head = list[0];
@@ -1060,25 +1079,9 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
10601079

10611080
shortlog_output(&log);
10621081

1063-
/*
1064-
* We can only do diffstat with a unique reference point
1065-
*/
1066-
if (!origin)
1067-
return;
1068-
1069-
memcpy(&opts, &rev->diffopt, sizeof(opts));
1070-
opts.output_format = DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
1071-
opts.stat_width = MAIL_DEFAULT_WRAP;
1072-
1073-
diff_setup_done(&opts);
1074-
1075-
diff_tree_oid(get_commit_tree_oid(origin),
1076-
get_commit_tree_oid(head),
1077-
"", &opts);
1078-
diffcore_std(&opts);
1079-
diff_flush(&opts);
1080-
1081-
fprintf(rev->diffopt.file, "\n");
1082+
/* We can only do diffstat with a unique reference point */
1083+
if (origin)
1084+
show_diffstat(rev, origin, head);
10821085
}
10831086

10841087
static const char *clean_message_id(const char *msg_id)

0 commit comments

Comments
 (0)