@matheusbsbs / matheus-bagliano / commits / 5b583e6a09
Fork 0

format-patch: pass notes configuration to range-diff

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>

Denton Liu committed Nov 20, 2019 at 13:18 UTC 5b583e6a09dc2095160a4489502577a5a20b400e
2 files changed +123 -2
builtin/log.c
+23 -1
@@ -1111,6 +1111,25 @@ do_pp:
1111 strbuf_release(&subject_sb);
1112 }
1113
1114 +static int get_notes_refs(struct string_list_item *item, void *arg)
1115 +{
1116 + argv_array_pushf(arg, "--notes=%s", item->string);
1117 + return 0;
1118 +}
1119 +
1120 +static void get_notes_args(struct argv_array *arg, struct rev_info *rev)
1121 +{
1122 + if (!rev->show_notes) {
1123 + argv_array_push(arg, "--no-notes");
1124 + } else if (rev->notes_opt.use_default_notes > 0 ||
1125 + (rev->notes_opt.use_default_notes == -1 &&
1126 + !rev->notes_opt.extra_notes_refs.nr)) {
1127 + argv_array_push(arg, "--notes");
1128 + } else {
1129 + for_each_string_list(&rev->notes_opt.extra_notes_refs, get_notes_refs, arg);
1130 + }
1131 +}
1132 +
1133 static void make_cover_letter(struct rev_info *rev, int use_stdout,
1134 struct commit *origin,
1135 int nr, struct commit **list,
@@ -1183,13 +1202,16 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
1202 * can be added later if deemed desirable.
1203 */
1204 struct diff_options opts;
1205 + struct argv_array other_arg = ARGV_ARRAY_INIT;
1206 diff_setup(&opts);
1207 opts.file = rev->diffopt.file;
1208 opts.use_color = rev->diffopt.use_color;
1209 diff_setup_done(&opts);
1210 fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
1211 + get_notes_args(&other_arg, rev);
1212 show_range_diff(rev->rdiff1, rev->rdiff2,
1192 - rev->creation_factor, 1, &opts, NULL);
1213 + rev->creation_factor, 1, &opts, &other_arg);
1214 + argv_array_clear(&other_arg);
1215 }
1216 }
1217
t/t3206-range-diff.sh
+100 -1
@@ -576,7 +576,7 @@ test_expect_success 'range-diff with multiple --notes' '
576 test_cmp expect actual
577 '
578
579 -test_expect_success 'format-patch --range-diff compares notes by default' '
579 +test_expect_success 'format-patch --range-diff does not compare notes by default' '
580 git notes add -m "topic note" topic &&
581 git notes add -m "unmodified note" unmodified &&
582 test_when_finished git notes remove topic unmodified &&
@@ -588,6 +588,40 @@ test_expect_success 'format-patch --range-diff compares notes by default' '
588 grep "= 1: .* s/5/A" 0000-* &&
589 grep "= 2: .* s/4/A" 0000-* &&
590 grep "= 3: .* s/11/B" 0000-* &&
591 + grep "= 4: .* s/12/B" 0000-* &&
592 + ! grep "Notes" 0000-* &&
593 + ! grep "note" 0000-*
594 +'
595 +
596 +test_expect_success 'format-patch --range-diff with --no-notes' '
597 + git notes add -m "topic note" topic &&
598 + git notes add -m "unmodified note" unmodified &&
599 + test_when_finished git notes remove topic unmodified &&
600 + git format-patch --no-notes --cover-letter --range-diff=$prev \
601 + master..unmodified >actual &&
602 + test_when_finished "rm 000?-*" &&
603 + test_line_count = 5 actual &&
604 + test_i18ngrep "^Range-diff:$" 0000-* &&
605 + grep "= 1: .* s/5/A" 0000-* &&
606 + grep "= 2: .* s/4/A" 0000-* &&
607 + grep "= 3: .* s/11/B" 0000-* &&
608 + grep "= 4: .* s/12/B" 0000-* &&
609 + ! grep "Notes" 0000-* &&
610 + ! grep "note" 0000-*
611 +'
612 +
613 +test_expect_success 'format-patch --range-diff with --notes' '
614 + git notes add -m "topic note" topic &&
615 + git notes add -m "unmodified note" unmodified &&
616 + test_when_finished git notes remove topic unmodified &&
617 + git format-patch --notes --cover-letter --range-diff=$prev \
618 + master..unmodified >actual &&
619 + test_when_finished "rm 000?-*" &&
620 + test_line_count = 5 actual &&
621 + test_i18ngrep "^Range-diff:$" 0000-* &&
622 + grep "= 1: .* s/5/A" 0000-* &&
623 + grep "= 2: .* s/4/A" 0000-* &&
624 + grep "= 3: .* s/11/B" 0000-* &&
625 grep "! 4: .* s/12/B" 0000-* &&
626 sed s/Z/\ /g >expect <<-EOF &&
627 @@ Commit message
@@ -604,4 +638,69 @@ test_expect_success 'format-patch --range-diff compares notes by default' '
638 test_cmp expect actual
639 '
640
641 +test_expect_success 'format-patch --range-diff with --notes' '
642 + git notes add -m "topic note" topic &&
643 + git notes add -m "unmodified note" unmodified &&
644 + test_when_finished git notes remove topic unmodified &&
645 + test_config format.notes true &&
646 + git format-patch --cover-letter --range-diff=$prev \
647 + master..unmodified >actual &&
648 + test_when_finished "rm 000?-*" &&
649 + test_line_count = 5 actual &&
650 + test_i18ngrep "^Range-diff:$" 0000-* &&
651 + grep "= 1: .* s/5/A" 0000-* &&
652 + grep "= 2: .* s/4/A" 0000-* &&
653 + grep "= 3: .* s/11/B" 0000-* &&
654 + grep "! 4: .* s/12/B" 0000-* &&
655 + sed s/Z/\ /g >expect <<-EOF &&
656 + @@ Commit message
657 + Z
658 + Z
659 + Z ## Notes ##
660 + - topic note
661 + + unmodified note
662 + Z
663 + Z ## file ##
664 + Z@@ file: A
665 + EOF
666 + sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
667 + test_cmp expect actual
668 +'
669 +
670 +test_expect_success 'format-patch --range-diff with multiple notes' '
671 + git notes --ref=note1 add -m "topic note1" topic &&
672 + git notes --ref=note1 add -m "unmodified note1" unmodified &&
673 + test_when_finished git notes --ref=note1 remove topic unmodified &&
674 + git notes --ref=note2 add -m "topic note2" topic &&
675 + git notes --ref=note2 add -m "unmodified note2" unmodified &&
676 + test_when_finished git notes --ref=note2 remove topic unmodified &&
677 + git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \
678 + master..unmodified >actual &&
679 + test_when_finished "rm 000?-*" &&
680 + test_line_count = 5 actual &&
681 + test_i18ngrep "^Range-diff:$" 0000-* &&
682 + grep "= 1: .* s/5/A" 0000-* &&
683 + grep "= 2: .* s/4/A" 0000-* &&
684 + grep "= 3: .* s/11/B" 0000-* &&
685 + grep "! 4: .* s/12/B" 0000-* &&
686 + sed s/Z/\ /g >expect <<-EOF &&
687 + @@ Commit message
688 + Z
689 + Z
690 + Z ## Notes (note1) ##
691 + - topic note1
692 + + unmodified note1
693 + Z
694 + Z
695 + Z ## Notes (note2) ##
696 + - topic note2
697 + + unmodified note2
698 + Z
699 + Z ## file ##
700 + Z@@ file: A
701 + EOF
702 + sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
703 + test_cmp expect actual
704 +'
705 +
706 test_done