Skip to content

Commit 4d8ae4d

Browse files
committed
Merge branch 'jc/format-patch-with-range-diff'
The inter/range-diff output has been moved to the end of the patch when format-patch adds it to a single patch, instead of writing it before the patch text, to be consistent with what is done for a cover letter for a multi-patch series. * jc/format-patch-with-range-diff: format-patch: move range/inter diff at the end of a single patch output show_log: factor out interdiff/range-diff generation
2 parents d63586c + 2fa04ce commit 4d8ae4d

File tree

2 files changed

+78
-47
lines changed

2 files changed

+78
-47
lines changed

log-tree.c

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,51 @@ static void next_commentary_block(struct rev_info *opt, struct strbuf *sb)
673673
opt->shown_dashes = 1;
674674
}
675675

676+
static void show_diff_of_diff(struct rev_info *opt)
677+
{
678+
if (!cmit_fmt_is_mail(opt->commit_format))
679+
return;
680+
681+
if (opt->idiff_oid1) {
682+
struct diff_queue_struct dq;
683+
684+
memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
685+
DIFF_QUEUE_CLEAR(&diff_queued_diff);
686+
687+
fprintf_ln(opt->diffopt.file, "\n%s", opt->idiff_title);
688+
show_interdiff(opt->idiff_oid1, opt->idiff_oid2, 2,
689+
&opt->diffopt);
690+
691+
memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
692+
}
693+
694+
if (opt->rdiff1) {
695+
struct diff_queue_struct dq;
696+
struct diff_options opts;
697+
struct range_diff_options range_diff_opts = {
698+
.creation_factor = opt->creation_factor,
699+
.dual_color = 1,
700+
.diffopt = &opts
701+
};
702+
703+
memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
704+
DIFF_QUEUE_CLEAR(&diff_queued_diff);
705+
706+
fprintf_ln(opt->diffopt.file, "\n%s", opt->rdiff_title);
707+
/*
708+
* Pass minimum required diff-options to range-diff; others
709+
* can be added later if deemed desirable.
710+
*/
711+
repo_diff_setup(the_repository, &opts);
712+
opts.file = opt->diffopt.file;
713+
opts.use_color = opt->diffopt.use_color;
714+
diff_setup_done(&opts);
715+
show_range_diff(opt->rdiff1, opt->rdiff2, &range_diff_opts);
716+
717+
memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
718+
}
719+
}
720+
676721
void show_log(struct rev_info *opt)
677722
{
678723
struct strbuf msgbuf = STRBUF_INIT;
@@ -856,47 +901,6 @@ void show_log(struct rev_info *opt)
856901
strbuf_release(&msgbuf);
857902
free(ctx.notes_message);
858903
free(ctx.after_subject);
859-
860-
if (cmit_fmt_is_mail(ctx.fmt) && opt->idiff_oid1) {
861-
struct diff_queue_struct dq;
862-
863-
memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
864-
DIFF_QUEUE_CLEAR(&diff_queued_diff);
865-
866-
next_commentary_block(opt, NULL);
867-
fprintf_ln(opt->diffopt.file, "%s", opt->idiff_title);
868-
show_interdiff(opt->idiff_oid1, opt->idiff_oid2, 2,
869-
&opt->diffopt);
870-
871-
memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
872-
}
873-
874-
if (cmit_fmt_is_mail(ctx.fmt) && opt->rdiff1) {
875-
struct diff_queue_struct dq;
876-
struct diff_options opts;
877-
struct range_diff_options range_diff_opts = {
878-
.creation_factor = opt->creation_factor,
879-
.dual_color = 1,
880-
.diffopt = &opts
881-
};
882-
883-
memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
884-
DIFF_QUEUE_CLEAR(&diff_queued_diff);
885-
886-
next_commentary_block(opt, NULL);
887-
fprintf_ln(opt->diffopt.file, "%s", opt->rdiff_title);
888-
/*
889-
* Pass minimum required diff-options to range-diff; others
890-
* can be added later if deemed desirable.
891-
*/
892-
repo_diff_setup(the_repository, &opts);
893-
opts.file = opt->diffopt.file;
894-
opts.use_color = opt->diffopt.use_color;
895-
diff_setup_done(&opts);
896-
show_range_diff(opt->rdiff1, opt->rdiff2, &range_diff_opts);
897-
898-
memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
899-
}
900904
}
901905

902906
int log_tree_diff_flush(struct rev_info *opt)
@@ -1165,9 +1169,12 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)
11651169
}
11661170
if (opt->track_linear && !opt->linear && opt->reverse_output_stage)
11671171
fprintf(opt->diffopt.file, "\n%s\n", opt->break_bar);
1172+
if (shown)
1173+
show_diff_of_diff(opt);
11681174
opt->loginfo = NULL;
11691175
maybe_flush_or_die(opt->diffopt.file, "stdout");
11701176
opt->diffopt.no_free = no_free;
1177+
11711178
diff_free(&opt->diffopt);
11721179
return shown;
11731180
}

t/t4014-format-patch.sh

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,13 +2482,37 @@ test_expect_success 'interdiff: reroll-count with a integer' '
24822482
'
24832483

24842484
test_expect_success 'interdiff: solo-patch' '
2485-
cat >expect <<-\EOF &&
2486-
+fleep
2487-
2488-
EOF
24892485
git format-patch --interdiff=boop~2 -1 boop &&
2490-
test_grep "^Interdiff:$" 0001-fleep.patch &&
2491-
sed "1,/^ @@ /d; /^$/q" 0001-fleep.patch >actual &&
2486+
2487+
# remove up to the last "patch" output line,
2488+
# and remove everything below the signature mark.
2489+
sed -e "1,/^+fleep\$/d" -e "/^-- /,\$d" 0001-fleep.patch >actual &&
2490+
2491+
# fabricate Interdiff output.
2492+
git diff boop~2 boop >inter &&
2493+
{
2494+
echo &&
2495+
echo "Interdiff:" &&
2496+
sed -e "s/^/ /" inter
2497+
} >expect &&
2498+
test_cmp expect actual
2499+
'
2500+
2501+
test_expect_success 'range-diff: solo-patch' '
2502+
git format-patch --creation-factor=999 \
2503+
--range-diff=boop~2..boop~1 -1 boop &&
2504+
2505+
# remove up to the last "patch" output line,
2506+
# and remove everything below the signature mark.
2507+
sed -e "1,/^+fleep\$/d" -e "/^-- /,\$d" 0001-fleep.patch >actual &&
2508+
2509+
# fabricate range-diff output.
2510+
{
2511+
echo &&
2512+
echo "Range-diff:" &&
2513+
git range-diff --creation-factor=999 \
2514+
boop~2..boop~1 boop~1..boop
2515+
} >expect &&
24922516
test_cmp expect actual
24932517
'
24942518

0 commit comments

Comments
 (0)