]> git.ipfire.org Git - thirdparty/git.git/commitdiff
format-patch: handle range-diff on notes correctly for single patches
authorKristoffer Haugsbakk <code@khaugsbakk.name>
Thu, 25 Sep 2025 17:07:36 +0000 (19:07 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Sep 2025 18:34:12 +0000 (11:34 -0700)
(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>
log-tree.c
t/t3206-range-diff.sh

index 73d21f71764e945c9be2348b3b7be78582360afa..3d38c748e45be9078587d1a14fb6dc436e61c53d 100644 (file)
@@ -718,7 +718,8 @@ static void show_diff_of_diff(struct rev_info *opt)
                        .creation_factor = opt->creation_factor,
                        .dual_color = 1,
                        .max_memory = RANGE_DIFF_MAX_MEMORY_DEFAULT,
-                       .diffopt = &opts
+                       .diffopt = &opts,
+                       .log_arg = &opt->rdiff_log_arg
                };
 
                memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
index e091df6d01da90cb705ff9f933290a6f409489d8..1e812df806bbbf27aad9bd3f175b4e6f45a0d988 100755 (executable)
@@ -707,7 +707,7 @@ test_expect_success 'format-patch --range-diff does not compare notes by default
        ! grep "note" 0000-*
 '
 
-test_expect_success 'format-patch --notes=custom --range-diff only compares custom notes' '
+test_expect_success 'format-patch --notes=custom --range-diff --cover-letter only compares custom notes' '
        test_when_finished "git notes remove topic unmodified || :" &&
        git notes add -m "topic note" topic &&
        git notes add -m "unmodified note" unmodified &&
@@ -721,6 +721,20 @@ test_expect_success 'format-patch --notes=custom --range-diff only compares cust
        ! grep "## Notes ##" 0000-*
 '
 
+# --range-diff on a single commit requires --no-cover-letter
+test_expect_success 'format-patch --notes=custom --range-diff on single commit only compares custom notes' '
+       test_when_finished "git notes remove HEAD unmodified || :" &&
+       git notes add -m "topic note" HEAD &&
+       test_when_finished "git notes --ref=custom remove HEAD unmodified || :" &&
+       git notes add -m "unmodified note" unmodified &&
+       git notes --ref=custom add -m "topic note (custom)" HEAD &&
+       git notes --ref=custom add -m "unmodified note (custom)" unmodified &&
+       git format-patch --notes=custom --range-diff=$prev \
+               -1 --stdout >actual &&
+       test_grep "## Notes (custom) ##" actual &&
+       test_grep ! "## Notes ##" actual
+'
+
 test_expect_success 'format-patch --range-diff with --no-notes' '
        test_when_finished "git notes remove topic unmodified || :" &&
        git notes add -m "topic note" topic &&