From cdffbdc217aba8a39d786a642d1376a5a605adec Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Tue, 8 Sep 2020 03:16:08 -0400 Subject: diff: move show_interdiff() from its own file to diff-lib show_interdiff() is a relatively small function and not likely to grow larger or more complicated. Rather than dedicating an entire source file to it, relocate it to diff-lib.c which houses other "take two things and compare them" functions meant to be re-used but not so low-level as to reside in the core diff implementation. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- diff-lib.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'diff-lib.c') diff --git a/diff-lib.c b/diff-lib.c index 50521e2093..9bab907412 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -571,3 +571,27 @@ int index_differs_from(struct repository *r, object_array_clear(&rev.pending); return (rev.diffopt.flags.has_changes != 0); } + +static struct strbuf *idiff_prefix_cb(struct diff_options *opt, void *data) +{ + return data; +} + +void show_interdiff(struct rev_info *rev, int indent) +{ + struct diff_options opts; + struct strbuf prefix = STRBUF_INIT; + + memcpy(&opts, &rev->diffopt, sizeof(opts)); + opts.output_format = DIFF_FORMAT_PATCH; + opts.output_prefix = idiff_prefix_cb; + strbuf_addchars(&prefix, ' ', indent); + opts.output_prefix_data = &prefix; + diff_setup_done(&opts); + + diff_tree_oid(rev->idiff_oid1, rev->idiff_oid2, "", &opts); + diffcore_std(&opts); + diff_flush(&opts); + + strbuf_release(&prefix); +} -- cgit v1.2.3 From 72a7239016fa4c8919a8b6932ad76e5f820389eb Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Tue, 8 Sep 2020 03:16:09 -0400 Subject: 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 Signed-off-by: Junio C Hamano --- diff-lib.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'diff-lib.c') diff --git a/diff-lib.c b/diff-lib.c index 9bab907412..a17becc509 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -577,19 +577,20 @@ static struct strbuf *idiff_prefix_cb(struct diff_options *opt, void *data) return data; } -void show_interdiff(struct rev_info *rev, int indent) +void show_interdiff(const struct object_id *oid1, const struct object_id *oid2, + int indent, struct diff_options *diffopt) { struct diff_options opts; struct strbuf prefix = STRBUF_INIT; - memcpy(&opts, &rev->diffopt, sizeof(opts)); + memcpy(&opts, diffopt, sizeof(opts)); opts.output_format = DIFF_FORMAT_PATCH; opts.output_prefix = idiff_prefix_cb; strbuf_addchars(&prefix, ' ', indent); opts.output_prefix_data = &prefix; diff_setup_done(&opts); - diff_tree_oid(rev->idiff_oid1, rev->idiff_oid2, "", &opts); + diff_tree_oid(oid1, oid2, "", &opts); diffcore_std(&opts); diff_flush(&opts); -- cgit v1.2.3