]> git.ipfire.org Git - thirdparty/git.git/commitdiff
format-patch: pass notes configuration to range-diff
authorDenton Liu <liu.denton@gmail.com>
Wed, 20 Nov 2019 21:18:47 +0000 (13:18 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Nov 2019 00:29:52 +0000 (09:29 +0900)
Since format-patch accepts `--[no-]notes`, one would expect the
range-diff generated to also respect the setting. Unfortunately, the
range-diff we currently generate only uses the default option (which
always outputs default notes, even when notes are not being used
elsewhere).

Pass the notes configuration to range-diff so that it can honor it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/log.c
t/t3206-range-diff.sh

index 047ac4594dbcddbb408273149f75fae72048da18..e192f219d9ab12119351642b8ec3ebee62759087 100644 (file)
@@ -1111,6 +1111,25 @@ do_pp:
        strbuf_release(&subject_sb);
 }
 
+static int get_notes_refs(struct string_list_item *item, void *arg)
+{
+       argv_array_pushf(arg, "--notes=%s", item->string);
+       return 0;
+}
+
+static void get_notes_args(struct argv_array *arg, struct rev_info *rev)
+{
+       if (!rev->show_notes) {
+               argv_array_push(arg, "--no-notes");
+       } else if (rev->notes_opt.use_default_notes > 0 ||
+                  (rev->notes_opt.use_default_notes == -1 &&
+                   !rev->notes_opt.extra_notes_refs.nr)) {
+               argv_array_push(arg, "--notes");
+       } else {
+               for_each_string_list(&rev->notes_opt.extra_notes_refs, get_notes_refs, arg);
+       }
+}
+
 static void make_cover_letter(struct rev_info *rev, int use_stdout,
                              struct commit *origin,
                              int nr, struct commit **list,
@@ -1183,13 +1202,16 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
                 * can be added later if deemed desirable.
                 */
                struct diff_options opts;
+               struct argv_array other_arg = ARGV_ARRAY_INIT;
                diff_setup(&opts);
                opts.file = rev->diffopt.file;
                opts.use_color = rev->diffopt.use_color;
                diff_setup_done(&opts);
                fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
+               get_notes_args(&other_arg, rev);
                show_range_diff(rev->rdiff1, rev->rdiff2,
-                               rev->creation_factor, 1, &opts, NULL);
+                               rev->creation_factor, 1, &opts, &other_arg);
+               argv_array_clear(&other_arg);
        }
 }
 
index 521b4a83ecbe5de5ac1a89fd9ea3929395b2d76e..ec2b456dbb8667eb7c7c1d423259639fe5f2853c 100755 (executable)
@@ -576,7 +576,7 @@ test_expect_success 'range-diff with multiple --notes' '
        test_cmp expect actual
 '
 
-test_expect_success 'format-patch --range-diff compares notes by default' '
+test_expect_success 'format-patch --range-diff does not compare notes by default' '
        git notes add -m "topic note" topic &&
        git notes add -m "unmodified note" unmodified &&
        test_when_finished git notes remove topic unmodified &&
@@ -588,6 +588,40 @@ test_expect_success 'format-patch --range-diff compares notes by default' '
        grep "= 1: .* s/5/A" 0000-* &&
        grep "= 2: .* s/4/A" 0000-* &&
        grep "= 3: .* s/11/B" 0000-* &&
+       grep "= 4: .* s/12/B" 0000-* &&
+       ! grep "Notes" 0000-* &&
+       ! grep "note" 0000-*
+'
+
+test_expect_success 'format-patch --range-diff with --no-notes' '
+       git notes add -m "topic note" topic &&
+       git notes add -m "unmodified note" unmodified &&
+       test_when_finished git notes remove topic unmodified &&
+       git format-patch --no-notes --cover-letter --range-diff=$prev \
+               master..unmodified >actual &&
+       test_when_finished "rm 000?-*" &&
+       test_line_count = 5 actual &&
+       test_i18ngrep "^Range-diff:$" 0000-* &&
+       grep "= 1: .* s/5/A" 0000-* &&
+       grep "= 2: .* s/4/A" 0000-* &&
+       grep "= 3: .* s/11/B" 0000-* &&
+       grep "= 4: .* s/12/B" 0000-* &&
+       ! grep "Notes" 0000-* &&
+       ! grep "note" 0000-*
+'
+
+test_expect_success 'format-patch --range-diff with --notes' '
+       git notes add -m "topic note" topic &&
+       git notes add -m "unmodified note" unmodified &&
+       test_when_finished git notes remove topic unmodified &&
+       git format-patch --notes --cover-letter --range-diff=$prev \
+               master..unmodified >actual &&
+       test_when_finished "rm 000?-*" &&
+       test_line_count = 5 actual &&
+       test_i18ngrep "^Range-diff:$" 0000-* &&
+       grep "= 1: .* s/5/A" 0000-* &&
+       grep "= 2: .* s/4/A" 0000-* &&
+       grep "= 3: .* s/11/B" 0000-* &&
        grep "! 4: .* s/12/B" 0000-* &&
        sed s/Z/\ /g >expect <<-EOF &&
            @@ Commit message
@@ -604,4 +638,69 @@ test_expect_success 'format-patch --range-diff compares notes by default' '
        test_cmp expect actual
 '
 
+test_expect_success 'format-patch --range-diff with --notes' '
+       git notes add -m "topic note" topic &&
+       git notes add -m "unmodified note" unmodified &&
+       test_when_finished git notes remove topic unmodified &&
+       test_config format.notes true &&
+       git format-patch --cover-letter --range-diff=$prev \
+               master..unmodified >actual &&
+       test_when_finished "rm 000?-*" &&
+       test_line_count = 5 actual &&
+       test_i18ngrep "^Range-diff:$" 0000-* &&
+       grep "= 1: .* s/5/A" 0000-* &&
+       grep "= 2: .* s/4/A" 0000-* &&
+       grep "= 3: .* s/11/B" 0000-* &&
+       grep "! 4: .* s/12/B" 0000-* &&
+       sed s/Z/\ /g >expect <<-EOF &&
+           @@ Commit message
+           Z
+           Z
+           Z ## Notes ##
+           -    topic note
+           +    unmodified note
+           Z
+           Z ## file ##
+           Z@@ file: A
+       EOF
+       sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'format-patch --range-diff with multiple notes' '
+       git notes --ref=note1 add -m "topic note1" topic &&
+       git notes --ref=note1 add -m "unmodified note1" unmodified &&
+       test_when_finished git notes --ref=note1 remove topic unmodified &&
+       git notes --ref=note2 add -m "topic note2" topic &&
+       git notes --ref=note2 add -m "unmodified note2" unmodified &&
+       test_when_finished git notes --ref=note2 remove topic unmodified &&
+       git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \
+               master..unmodified >actual &&
+       test_when_finished "rm 000?-*" &&
+       test_line_count = 5 actual &&
+       test_i18ngrep "^Range-diff:$" 0000-* &&
+       grep "= 1: .* s/5/A" 0000-* &&
+       grep "= 2: .* s/4/A" 0000-* &&
+       grep "= 3: .* s/11/B" 0000-* &&
+       grep "! 4: .* s/12/B" 0000-* &&
+       sed s/Z/\ /g >expect <<-EOF &&
+           @@ Commit message
+           Z
+           Z
+           Z ## Notes (note1) ##
+           -    topic note1
+           +    unmodified note1
+           Z
+           Z
+           Z ## Notes (note2) ##
+           -    topic note2
+           +    unmodified note2
+           Z
+           Z ## file ##
+           Z@@ file: A
+       EOF
+       sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
+       test_cmp expect actual
+'
+
 test_done