Skip to content

Commit 2fa04ce

Browse files
committed
format-patch: move range/inter diff at the end of a single patch output
When running "format-patch" on a multiple patch series, the output coming from "--interdiff" and "--range-diff" options is inserted after the "shortlog" list of commits and the overall diffstat. The idea is that shortlog/diffstat are shorter and with denser information content, which gives a better overview before the readers dive into more details of range/inter diff. When working on a single patch, however, we stuff the inter/range diff output before the actual patch, next to the diffstat. This pushes down the patch text way down with inter/range diff output, distracting readers. Move the inter/range diff output to the very end of the output, after all the patch text is shown. As the inter/range diff is no longer part of the commentary block (i.e., what comes after the log message and "---", but before the patch text), stop producing "---" in the function that generates them. But to separate it out visually (note: this is not needed to help tools like "git apply" that pay attention to the hunk headers to figure out the length of the hunks), add an extra blank line between the end of the patch text and the inter/range diff. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 84ed505 commit 2fa04ce

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

log-tree.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,7 @@ static void show_diff_of_diff(struct rev_info *opt)
684684
memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
685685
DIFF_QUEUE_CLEAR(&diff_queued_diff);
686686

687-
next_commentary_block(opt, NULL);
688-
fprintf_ln(opt->diffopt.file, "%s", opt->idiff_title);
687+
fprintf_ln(opt->diffopt.file, "\n%s", opt->idiff_title);
689688
show_interdiff(opt->idiff_oid1, opt->idiff_oid2, 2,
690689
&opt->diffopt);
691690

@@ -704,8 +703,7 @@ static void show_diff_of_diff(struct rev_info *opt)
704703
memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
705704
DIFF_QUEUE_CLEAR(&diff_queued_diff);
706705

707-
next_commentary_block(opt, NULL);
708-
fprintf_ln(opt->diffopt.file, "%s", opt->rdiff_title);
706+
fprintf_ln(opt->diffopt.file, "\n%s", opt->rdiff_title);
709707
/*
710708
* Pass minimum required diff-options to range-diff; others
711709
* can be added later if deemed desirable.
@@ -903,8 +901,6 @@ void show_log(struct rev_info *opt)
903901
strbuf_release(&msgbuf);
904902
free(ctx.notes_message);
905903
free(ctx.after_subject);
906-
907-
show_diff_of_diff(opt);
908904
}
909905

910906
int log_tree_diff_flush(struct rev_info *opt)
@@ -1173,9 +1169,12 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)
11731169
}
11741170
if (opt->track_linear && !opt->linear && opt->reverse_output_stage)
11751171
fprintf(opt->diffopt.file, "\n%s\n", opt->break_bar);
1172+
if (shown)
1173+
show_diff_of_diff(opt);
11761174
opt->loginfo = NULL;
11771175
maybe_flush_or_die(opt->diffopt.file, "stdout");
11781176
opt->diffopt.no_free = no_free;
1177+
11791178
diff_free(&opt->diffopt);
11801179
return shown;
11811180
}

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)