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>
This commit is contained in:
parent
bd36191886
commit
5b583e6a09
@ -1111,6 +1111,25 @@ do_pp:
|
|||||||
strbuf_release(&subject_sb);
|
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,
|
static void make_cover_letter(struct rev_info *rev, int use_stdout,
|
||||||
struct commit *origin,
|
struct commit *origin,
|
||||||
int nr, struct commit **list,
|
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.
|
* can be added later if deemed desirable.
|
||||||
*/
|
*/
|
||||||
struct diff_options opts;
|
struct diff_options opts;
|
||||||
|
struct argv_array other_arg = ARGV_ARRAY_INIT;
|
||||||
diff_setup(&opts);
|
diff_setup(&opts);
|
||||||
opts.file = rev->diffopt.file;
|
opts.file = rev->diffopt.file;
|
||||||
opts.use_color = rev->diffopt.use_color;
|
opts.use_color = rev->diffopt.use_color;
|
||||||
diff_setup_done(&opts);
|
diff_setup_done(&opts);
|
||||||
fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
|
fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
|
||||||
|
get_notes_args(&other_arg, rev);
|
||||||
show_range_diff(rev->rdiff1, rev->rdiff2,
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -576,7 +576,7 @@ test_expect_success 'range-diff with multiple --notes' '
|
|||||||
test_cmp expect actual
|
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 "topic note" topic &&
|
||||||
git notes add -m "unmodified note" unmodified &&
|
git notes add -m "unmodified note" unmodified &&
|
||||||
test_when_finished git notes remove topic unmodified &&
|
test_when_finished git notes remove topic unmodified &&
|
||||||
@ -588,6 +588,69 @@ test_expect_success 'format-patch --range-diff compares notes by default' '
|
|||||||
grep "= 1: .* s/5/A" 0000-* &&
|
grep "= 1: .* s/5/A" 0000-* &&
|
||||||
grep "= 2: .* s/4/A" 0000-* &&
|
grep "= 2: .* s/4/A" 0000-* &&
|
||||||
grep "= 3: .* s/11/B" 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
|
||||||
|
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 --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-* &&
|
grep "! 4: .* s/12/B" 0000-* &&
|
||||||
sed s/Z/\ /g >expect <<-EOF &&
|
sed s/Z/\ /g >expect <<-EOF &&
|
||||||
@@ Commit message
|
@@ Commit message
|
||||||
@ -604,4 +667,40 @@ test_expect_success 'format-patch --range-diff compares notes by default' '
|
|||||||
test_cmp expect 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
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user