Skip to content

Commit ac0edf1

Browse files
Martin Ågrengitster
authored andcommitted
range-diff: always pass at least minimal diff options
Commit d8981c3 ("format-patch: do not let its diff-options affect --range-diff", 2018-11-30) taught `show_range_diff()` to accept a NULL-pointer as an indication that it should use its own "reasonable default". That fixed a regression from a517079 ("Merge branch 'ab/range-diff-no-patch'", 2018-11-18), but unfortunately it introduced a regression of its own. In particular, it means we forget the `file` member of the diff options, so rather than placing a range-diff in the cover-letter, we write it to stdout. In order to fix this, rewrite the two callers adjusted by d8981c3 to instead create a "dummy" set of diff options where they only fill in the fields we absolutely require, such as output file and color. Modify and extend the existing tests to try and verify that the right contents end up in the right place. Don't revert `show_range_diff()`, i.e., let it keep accepting NULL. Rather than removing what is dead code and figuring out it isn't actually dead and we've broken 2.20, just leave it for now. [es: retain diff coloring when going to stdout] Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d8981c3 commit ac0edf1

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

builtin/log.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,9 +1094,18 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
10941094
}
10951095

10961096
if (rev->rdiff1) {
1097+
/*
1098+
* Pass minimum required diff-options to range-diff; others
1099+
* can be added later if deemed desirable.
1100+
*/
1101+
struct diff_options opts;
1102+
diff_setup(&opts);
1103+
opts.file = rev->diffopt.file;
1104+
opts.use_color = rev->diffopt.use_color;
1105+
diff_setup_done(&opts);
10971106
fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
10981107
show_range_diff(rev->rdiff1, rev->rdiff2,
1099-
rev->creation_factor, 1, NULL);
1108+
rev->creation_factor, 1, &opts);
11001109
}
11011110
}
11021111

log-tree.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,14 +755,23 @@ void show_log(struct rev_info *opt)
755755

756756
if (cmit_fmt_is_mail(ctx.fmt) && opt->rdiff1) {
757757
struct diff_queue_struct dq;
758+
struct diff_options opts;
758759

759760
memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
760761
DIFF_QUEUE_CLEAR(&diff_queued_diff);
761762

762763
next_commentary_block(opt, NULL);
763764
fprintf_ln(opt->diffopt.file, "%s", opt->rdiff_title);
765+
/*
766+
* Pass minimum required diff-options to range-diff; others
767+
* can be added later if deemed desirable.
768+
*/
769+
diff_setup(&opts);
770+
opts.file = opt->diffopt.file;
771+
opts.use_color = opt->diffopt.use_color;
772+
diff_setup_done(&opts);
764773
show_range_diff(opt->rdiff1, opt->rdiff2,
765-
opt->creation_factor, 1, NULL);
774+
opt->creation_factor, 1, &opts);
766775

767776
memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
768777
}

t/t3206-range-diff.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,24 @@ test_expect_success 'dual-coloring' '
248248
for prev in topic master..topic
249249
do
250250
test_expect_success "format-patch --range-diff=$prev" '
251-
git format-patch --stdout --cover-letter --range-diff=$prev \
251+
git format-patch --cover-letter --range-diff=$prev \
252252
master..unmodified >actual &&
253-
grep "= 1: .* s/5/A" actual &&
254-
grep "= 2: .* s/4/A" actual &&
255-
grep "= 3: .* s/11/B" actual &&
256-
grep "= 4: .* s/12/B" actual
253+
test_when_finished "rm 000?-*" &&
254+
test_line_count = 5 actual &&
255+
test_i18ngrep "^Range-diff:$" 0000-* &&
256+
grep "= 1: .* s/5/A" 0000-* &&
257+
grep "= 2: .* s/4/A" 0000-* &&
258+
grep "= 3: .* s/11/B" 0000-* &&
259+
grep "= 4: .* s/12/B" 0000-*
257260
'
258261
done
259262

260263
test_expect_success 'format-patch --range-diff as commentary' '
261-
git format-patch --stdout --range-diff=HEAD~1 HEAD~1 >actual &&
262-
test_i18ngrep "^Range-diff:$" actual
264+
git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
265+
test_when_finished "rm 0001-*" &&
266+
test_line_count = 1 actual &&
267+
test_i18ngrep "^Range-diff:$" 0001-* &&
268+
grep "> 1: .* new message" 0001-*
263269
'
264270

265271
test_done

0 commit comments

Comments
 (0)