Skip to content

Commit 3b02641

Browse files
sunshinecogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ac290f commit 3b02641

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

builtin/log.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
10861086

10871087
if (rev->idiff_oid1) {
10881088
fprintf_ln(rev->diffopt.file, "%s", rev->idiff_title);
1089-
show_interdiff(rev);
1089+
show_interdiff(rev, 0);
10901090
}
10911091
}
10921092

interdiff.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,26 @@
33
#include "revision.h"
44
#include "interdiff.h"
55

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)
712
{
813
struct diff_options opts;
14+
struct strbuf prefix = STRBUF_INIT;
915

1016
memcpy(&opts, &rev->diffopt, sizeof(opts));
1117
opts.output_format = DIFF_FORMAT_PATCH;
18+
opts.output_prefix = idiff_prefix_cb;
19+
strbuf_addchars(&prefix, ' ', indent);
20+
opts.output_prefix_data = &prefix;
1221
diff_setup_done(&opts);
1322

1423
diff_tree_oid(rev->idiff_oid1, rev->idiff_oid2, "", &opts);
1524
diffcore_std(&opts);
1625
diff_flush(&opts);
26+
27+
strbuf_release(&prefix);
1728
}

interdiff.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
struct rev_info;
55

6-
void show_interdiff(struct rev_info *);
6+
void show_interdiff(struct rev_info *, int indent);
77

88
#endif

0 commit comments

Comments
 (0)