Skip to content

Commit 72a7239

Browse files
sunshinecogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cdffbdc commit 72a7239

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

builtin/log.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
12061206

12071207
if (rev->idiff_oid1) {
12081208
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);
12101211
}
12111212

12121213
if (rev->rdiff1) {

diff-lib.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,19 +577,20 @@ static struct strbuf *idiff_prefix_cb(struct diff_options *opt, void *data)
577577
return data;
578578
}
579579

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)
581582
{
582583
struct diff_options opts;
583584
struct strbuf prefix = STRBUF_INIT;
584585

585-
memcpy(&opts, &rev->diffopt, sizeof(opts));
586+
memcpy(&opts, diffopt, sizeof(opts));
586587
opts.output_format = DIFF_FORMAT_PATCH;
587588
opts.output_prefix = idiff_prefix_cb;
588589
strbuf_addchars(&prefix, ' ', indent);
589590
opts.output_prefix_data = &prefix;
590591
diff_setup_done(&opts);
591592

592-
diff_tree_oid(rev->idiff_oid1, rev->idiff_oid2, "", &opts);
593+
diff_tree_oid(oid1, oid2, "", &opts);
593594
diffcore_std(&opts);
594595
diff_flush(&opts);
595596

diff.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,12 @@ int index_differs_from(struct repository *r, const char *def,
600600
const struct diff_flags *flags,
601601
int ita_invisible_in_index);
602602

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 *);
604609

605610
/*
606611
* Fill the contents of the filespec "df", respecting any textconv defined by

log-tree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,8 @@ void show_log(struct rev_info *opt)
799799

800800
next_commentary_block(opt, NULL);
801801
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);
803804

804805
memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
805806
}

0 commit comments

Comments
 (0)