Skip to content

Commit 5b583e6

Browse files
Denton-Lgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bd36191 commit 5b583e6

File tree

2 files changed

+123
-2
lines changed

2 files changed

+123
-2
lines changed

builtin/log.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,25 @@ static void prepare_cover_text(struct pretty_print_context *pp,
11111111
strbuf_release(&subject_sb);
11121112
}
11131113

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+
11141133
static void make_cover_letter(struct rev_info *rev, int use_stdout,
11151134
struct commit *origin,
11161135
int nr, struct commit **list,
@@ -1183,13 +1202,16 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
11831202
* can be added later if deemed desirable.
11841203
*/
11851204
struct diff_options opts;
1205+
struct argv_array other_arg = ARGV_ARRAY_INIT;
11861206
diff_setup(&opts);
11871207
opts.file = rev->diffopt.file;
11881208
opts.use_color = rev->diffopt.use_color;
11891209
diff_setup_done(&opts);
11901210
fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
1211+
get_notes_args(&other_arg, rev);
11911212
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);
11931215
}
11941216
}
11951217

t/t3206-range-diff.sh

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ test_expect_success 'range-diff with multiple --notes' '
576576
test_cmp expect actual
577577
'
578578

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' '
580580
git notes add -m "topic note" topic &&
581581
git notes add -m "unmodified note" unmodified &&
582582
test_when_finished git notes remove topic unmodified &&
@@ -588,6 +588,40 @@ test_expect_success 'format-patch --range-diff compares notes by default' '
588588
grep "= 1: .* s/5/A" 0000-* &&
589589
grep "= 2: .* s/4/A" 0000-* &&
590590
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-* &&
591625
grep "! 4: .* s/12/B" 0000-* &&
592626
sed s/Z/\ /g >expect <<-EOF &&
593627
@@ Commit message
@@ -604,4 +638,69 @@ test_expect_success 'format-patch --range-diff compares notes by default' '
604638
test_cmp expect actual
605639
'
606640

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+
607706
test_done

0 commit comments

Comments
 (0)