interdiff: teach show_interdiff() to indent interdiff

A future change will allow "git format-patch --interdiff=<prev> -1" to insert an interdiff into the commentary section of the lone patch of a 1-patch series. However, to prevent the inserted interdiff from confusing git-am, as well as human readers, it needs to be indented. Therefore, teach show_interdiff() how to indent. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Jul 22, 2018 at 05:57 UTC 3b026417eaa1f32f53b85d1b131194ae1cbbf068
3 files changed +14 -3
builtin/log.c
+1 -1
@@ -1086,7 +1086,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
1086
1087 if (rev->idiff_oid1) {
1088 fprintf_ln(rev->diffopt.file, "%s", rev->idiff_title);
1089 - show_interdiff(rev);
1089 + show_interdiff(rev, 0);
1090 }
1091 }
1092
interdiff.c
+12 -1
@@ -3,15 +3,26 @@
3 #include "revision.h"
4 #include "interdiff.h"
5
6 -void show_interdiff(struct rev_info *rev)
6 +static struct strbuf *idiff_prefix_cb(struct diff_options *opt, void *data)
7 +{
8 + return data;
9 +}
10 +
11 +void show_interdiff(struct rev_info *rev, int indent)
12 {
13 struct diff_options opts;
14 + struct strbuf prefix = STRBUF_INIT;
15
16 memcpy(&opts, &rev->diffopt, sizeof(opts));
17 opts.output_format = DIFF_FORMAT_PATCH;
18 + opts.output_prefix = idiff_prefix_cb;
19 + strbuf_addchars(&prefix, ' ', indent);
20 + opts.output_prefix_data = &prefix;
21 diff_setup_done(&opts);
22
23 diff_tree_oid(rev->idiff_oid1, rev->idiff_oid2, "", &opts);
24 diffcore_std(&opts);
25 diff_flush(&opts);
26 +
27 + strbuf_release(&prefix);
28 }
interdiff.h
+1 -1
@@ -3,6 +3,6 @@
3
4 struct rev_info;
5
6 -void show_interdiff(struct rev_info *);
6 +void show_interdiff(struct rev_info *, int indent);
7
8 #endif