@matheusbsbs / matheus-bagliano / commits / 72a7239016
Fork 0

diff-lib: tighten show_interdiff()'s interface

To compute and show an interdiff, show_interdiff() needs only the two OID's to compare and a diffopts, yet it expects callers to supply an entire rev_info. The demand for rev_info is not only overkill, but also places unnecessary burden on potential future callers which might not otherwise have a rev_info at hand. Address this by tightening its signature to require only the items it needs instead of a full rev_info. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Sep 8, 2020 at 03:16 UTC 72a7239016fa4c8919a8b6932ad76e5f820389eb
4 files changed +14 -6
builtin/log.c
+2 -1
@@ -1206,7 +1206,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
1206
1207 if (rev->idiff_oid1) {
1208 fprintf_ln(rev->diffopt.file, "%s", rev->idiff_title);
1209 - show_interdiff(rev, 0);
1209 + show_interdiff(rev->idiff_oid1, rev->idiff_oid2, 0,
1210 + &rev->diffopt);
1211 }
1212
1213 if (rev->rdiff1) {
diff-lib.c
+4 -3
@@ -577,19 +577,20 @@ static struct strbuf *idiff_prefix_cb(struct diff_options *opt, void *data)
577 return data;
578 }
579
580 -void show_interdiff(struct rev_info *rev, int indent)
580 +void show_interdiff(const struct object_id *oid1, const struct object_id *oid2,
581 + int indent, struct diff_options *diffopt)
582 {
583 struct diff_options opts;
584 struct strbuf prefix = STRBUF_INIT;
585
585 - memcpy(&opts, &rev->diffopt, sizeof(opts));
586 + memcpy(&opts, diffopt, sizeof(opts));
587 opts.output_format = DIFF_FORMAT_PATCH;
588 opts.output_prefix = idiff_prefix_cb;
589 strbuf_addchars(&prefix, ' ', indent);
590 opts.output_prefix_data = &prefix;
591 diff_setup_done(&opts);
592
592 - diff_tree_oid(rev->idiff_oid1, rev->idiff_oid2, "", &opts);
593 + diff_tree_oid(oid1, oid2, "", &opts);
594 diffcore_std(&opts);
595 diff_flush(&opts);
596
diff.h
+6 -1
@@ -600,7 +600,12 @@ int index_differs_from(struct repository *r, const char *def,
600 const struct diff_flags *flags,
601 int ita_invisible_in_index);
602
603 -void show_interdiff(struct rev_info *, int indent);
603 +/*
604 + * Emit an interdiff of two object ID's to 'diff_options.file' optionally
605 + * indented by 'indent' spaces.
606 + */
607 +void show_interdiff(const struct object_id *, const struct object_id *,
608 + int indent, struct diff_options *);
609
610 /*
611 * Fill the contents of the filespec "df", respecting any textconv defined by
log-tree.c
+2 -1
@@ -799,7 +799,8 @@ void show_log(struct rev_info *opt)
799
800 next_commentary_block(opt, NULL);
801 fprintf_ln(opt->diffopt.file, "%s", opt->idiff_title);
802 - show_interdiff(opt, 2);
802 + show_interdiff(opt->idiff_oid1, opt->idiff_oid2, 2,
803 + &opt->diffopt);
804
805 memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
806 }