]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff-lib: tighten show_interdiff()'s interface
authorEric Sunshine <sunshine@sunshineco.com>
Tue, 8 Sep 2020 07:16:09 +0000 (03:16 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Sep 2020 22:03:27 +0000 (15:03 -0700)
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>
builtin/log.c
diff-lib.c
diff.h
log-tree.c

index ae9380da1be28237e30760f07134d3f75c0a627f..37177b3e7fc1eadb7fd2dd0e59595d85f1b72af9 100644 (file)
@@ -1206,7 +1206,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
 
        if (rev->idiff_oid1) {
                fprintf_ln(rev->diffopt.file, "%s", rev->idiff_title);
-               show_interdiff(rev, 0);
+               show_interdiff(rev->idiff_oid1, rev->idiff_oid2, 0,
+                              &rev->diffopt);
        }
 
        if (rev->rdiff1) {
index 9bab9074120fa5eff566aa4262ad7a5de1bbf6e5..a17becc509ca36daf44da02ad17a40a297dff7de 100644 (file)
@@ -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);
 
diff --git a/diff.h b/diff.h
index 308937c94ba5c76e68c4becb799f8c4842542c4a..49242d2733c08de0fa19ee32eb04a3b7f5c9eaae 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -600,7 +600,12 @@ int index_differs_from(struct repository *r, const char *def,
                       const struct diff_flags *flags,
                       int ita_invisible_in_index);
 
-void show_interdiff(struct rev_info *, int indent);
+/*
+ * Emit an interdiff of two object ID's to 'diff_options.file' optionally
+ * indented by 'indent' spaces.
+ */
+void show_interdiff(const struct object_id *, const struct object_id *,
+                   int indent, struct diff_options *);
 
 /*
  * Fill the contents of the filespec "df", respecting any textconv defined by
index 39bb362d5e5e486db54db1adc79577605f74ac7e..ad1e7e31f8781d86fa106deb45f10d50edf8daf8 100644 (file)
@@ -799,7 +799,8 @@ void show_log(struct rev_info *opt)
 
                next_commentary_block(opt, NULL);
                fprintf_ln(opt->diffopt.file, "%s", opt->idiff_title);
-               show_interdiff(opt, 2);
+               show_interdiff(opt->idiff_oid1, opt->idiff_oid2, 2,
+                              &opt->diffopt);
 
                memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
        }