format-patch: handle range-diff on notes correctly for single patches

(The two next paragraphs are taken from the previous commit.) git-format-patch(1) supports Git notes by showing them beneath the patch/commit message, similar to git-log(1). The command also supports showing those same notes ref names in the range diff output. Note *the same* ref names; any Git notes options or configuration variables need to be handed off to the range-diff machinery. This works correctly in the case when the range diff is on the cover letter. But it does not work correctly when the output is a single patch with an embedded range diff. Concretely, git-format-patch(1) needs to pass `--[no-]notes` options on to the range-diff subprocess in `range-diff.c`. Range diffs for single- commit series are handled in `log-tree.c`. But `log-tree.c` had no access to any `log_arg` variable before we added it to `rev_info` in the previous commit. Use that new struct member to fix this inconsistency. Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kristoffer Haugsbakk committed Sep 25, 2025 at 19:07 UTC 155986b49b52b9b5910edc0fd56ba46f0f1bed22
2 files changed +17 -2
log-tree.c
+2 -1
@@ -718,7 +718,8 @@ static void show_diff_of_diff(struct rev_info *opt)
718 .creation_factor = opt->creation_factor,
719 .dual_color = 1,
720 .max_memory = RANGE_DIFF_MAX_MEMORY_DEFAULT,
721 - .diffopt = &opts
721 + .diffopt = &opts,
722 + .log_arg = &opt->rdiff_log_arg
723 };
724
725 memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
t/t3206-range-diff.sh
+15 -1
@@ -707,7 +707,7 @@ test_expect_success 'format-patch --range-diff does not compare notes by default
707 ! grep "note" 0000-*
708 '
709
710 -test_expect_success 'format-patch --notes=custom --range-diff only compares custom notes' '
710 +test_expect_success 'format-patch --notes=custom --range-diff --cover-letter only compares custom notes' '
711 test_when_finished "git notes remove topic unmodified || :" &&
712 git notes add -m "topic note" topic &&
713 git notes add -m "unmodified note" unmodified &&
@@ -721,6 +721,20 @@ test_expect_success 'format-patch --notes=custom --range-diff only compares cust
721 ! grep "## Notes ##" 0000-*
722 '
723
724 +# --range-diff on a single commit requires --no-cover-letter
725 +test_expect_success 'format-patch --notes=custom --range-diff on single commit only compares custom notes' '
726 + test_when_finished "git notes remove HEAD unmodified || :" &&
727 + git notes add -m "topic note" HEAD &&
728 + test_when_finished "git notes --ref=custom remove HEAD unmodified || :" &&
729 + git notes add -m "unmodified note" unmodified &&
730 + git notes --ref=custom add -m "topic note (custom)" HEAD &&
731 + git notes --ref=custom add -m "unmodified note (custom)" unmodified &&
732 + git format-patch --notes=custom --range-diff=$prev \
733 + -1 --stdout >actual &&
734 + test_grep "## Notes (custom) ##" actual &&
735 + test_grep ! "## Notes ##" actual
736 +'
737 +
738 test_expect_success 'format-patch --range-diff with --no-notes' '
739 test_when_finished "git notes remove topic unmodified || :" &&
740 git notes add -m "topic note" topic &&