Skip to content

Commit 707b34c

Browse files
committed
Merge branch 'kh/format-patch-range-diff-notes' into seen
The 'format-patch' command has been updated with options to configure notes specifically for range-diff output, allowing them to differ from the notes displayed on the patches themselves. * kh/format-patch-range-diff-notes: format-patch: learn --[no-]range-diff-notes revision.h: rename struct member to reflect notes role format-patch: simplify get_notes_arg parameters
2 parents 028b09b + 98d7326 commit 707b34c

6 files changed

Lines changed: 156 additions & 11 deletions

File tree

Documentation/git-format-patch.adoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,23 @@ case is to show comparison with an older iteration of the same
378378
topic and the tool should find more correspondence between the two
379379
sets of patches.
380380
381+
`--range-diff-notes[=<ref>]`::
382+
`--no-range-diff-notes`::
383+
Used with `--range-diff`, tweak what notes to display in the
384+
range diff. For example, you can use `--no-range-diff-notes` to
385+
turn off all notes in the range diff. The default behavior is
386+
to display the same notes in the range diff as on the patches
387+
(see `--notes`).
388+
+
389+
You may want to turn off this notes override after it has been
390+
activated. Use this sequence to do that:
391+
+
392+
----
393+
--no-range-diff-notes --range-diff-notes
394+
----
395+
+
396+
Now the range diff is back to displaying the same notes as the patches.
397+
381398
`--notes[=<ref>]`::
382399
`--no-notes`::
383400
Append the notes (see linkgit:git-notes[1]) for the commit

builtin/log.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,16 +1341,21 @@ static int get_notes_refs(struct string_list_item *item, void *arg)
13411341
return 0;
13421342
}
13431343

1344-
static void get_notes_args(struct strvec *arg, struct rev_info *rev)
1344+
static void get_notes_args(struct rev_info *rev)
13451345
{
1346-
if (!rev->show_notes) {
1347-
strvec_push(arg, "--no-notes");
1346+
if (rev->rdiff_override_notes) {
1347+
if (!rev->rdiff_notes_arg.nr)
1348+
strvec_push(&rev->rdiff_notes_arg, "--no-notes");
1349+
} else if (!rev->show_notes) {
1350+
strvec_push(&rev->rdiff_notes_arg, "--no-notes");
13481351
} else if (rev->notes_opt.use_default_notes > 0 ||
13491352
(rev->notes_opt.use_default_notes == -1 &&
13501353
!rev->notes_opt.extra_notes_refs.nr)) {
1351-
strvec_push(arg, "--notes");
1354+
strvec_push(&rev->rdiff_notes_arg, "--notes");
13521355
} else {
1353-
for_each_string_list(&rev->notes_opt.extra_notes_refs, get_notes_refs, arg);
1356+
for_each_string_list(&rev->notes_opt.extra_notes_refs,
1357+
get_notes_refs,
1358+
&rev->rdiff_notes_arg);
13541359
}
13551360
}
13561361

@@ -1481,7 +1486,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
14811486
.dual_color = 1,
14821487
.max_memory = RANGE_DIFF_MAX_MEMORY_DEFAULT,
14831488
.diffopt = &opts,
1484-
.log_arg = &rev->rdiff_log_arg
1489+
.log_arg = &rev->rdiff_notes_arg
14851490
};
14861491

14871492
repo_diff_setup(the_repository, &opts);
@@ -2423,7 +2428,7 @@ int cmd_format_patch(int argc,
24232428
rev.rdiff_title = diff_title(&rdiff_title, reroll_count,
24242429
_("Range-diff:"),
24252430
_("Range-diff against v%d:"));
2426-
get_notes_args(&(rev.rdiff_log_arg), &rev);
2431+
get_notes_args(&rev);
24272432
}
24282433

24292434
/*
@@ -2586,7 +2591,7 @@ int cmd_format_patch(int argc,
25862591
rev.diffopt.no_free = 0;
25872592
release_revisions(&rev);
25882593
format_config_release(&cfg);
2589-
strvec_clear(&rev.rdiff_log_arg);
2594+
strvec_clear(&rev.rdiff_notes_arg);
25902595
return 0;
25912596
}
25922597

log-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ static void show_diff_of_diff(struct rev_info *opt)
718718
.dual_color = 1,
719719
.max_memory = RANGE_DIFF_MAX_MEMORY_DEFAULT,
720720
.diffopt = &opts,
721-
.log_arg = &opt->rdiff_log_arg
721+
.log_arg = &opt->rdiff_notes_arg
722722
};
723723

724724
memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));

revision.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2653,6 +2653,19 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
26532653
revs->notes_opt.use_default_notes = 1;
26542654
} else if (!strcmp(arg, "--no-standard-notes")) {
26552655
revs->notes_opt.use_default_notes = 0;
2656+
} else if (!strcmp(arg, "--no-range-diff-notes")) {
2657+
strvec_clear(&revs->rdiff_notes_arg);
2658+
revs->rdiff_override_notes = 1;
2659+
} else if (!strcmp(arg, "--range-diff-notes")) {
2660+
/*
2661+
* Allow the user to use '--no-range-diff-notes
2662+
* --range-diff-notes' in order to go back to
2663+
* using the 'format-patch' notes behavior
2664+
*/
2665+
revs->rdiff_override_notes = revs->rdiff_notes_arg.nr;
2666+
} else if (skip_prefix(arg, "--range-diff-notes=", &optarg)) {
2667+
strvec_pushf(&revs->rdiff_notes_arg, "--notes=%s", optarg);
2668+
revs->rdiff_override_notes = 1;
26562669
} else if (!strcmp(arg, "--oneline")) {
26572670
revs->verbose_header = 1;
26582671
get_commit_format("oneline", revs);

revision.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,12 @@ struct rev_info {
352352
/* range-diff */
353353
const char *rdiff1;
354354
const char *rdiff2;
355-
struct strvec rdiff_log_arg;
355+
/*
356+
* whether to use 'rdiff_notes_arg' or inherited
357+
* notes behavior
358+
*/
359+
bool rdiff_override_notes;
360+
struct strvec rdiff_notes_arg;
356361
int creation_factor;
357362
const char *rdiff_title;
358363

@@ -433,7 +438,7 @@ struct rev_info {
433438
.expand_tabs_in_log = -1, \
434439
.commit_format = CMIT_FMT_DEFAULT, \
435440
.expand_tabs_in_log_default = 8, \
436-
.rdiff_log_arg = STRVEC_INIT, \
441+
.rdiff_notes_arg = STRVEC_INIT, \
437442
}
438443

439444
/**

t/t3206-range-diff.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,111 @@ test_expect_success 'format-patch --range-diff with multiple notes' '
845845
test_cmp expect actual
846846
'
847847

848+
test_expect_success 'format-patch --range-diff --notes=custom --no-range-diff-notes' '
849+
test_when_finished "git notes --ref=custom remove topic unmodified || :" &&
850+
git notes --ref=custom add -m "topic note1" topic &&
851+
git notes --ref=custom add -m "unmodified note1" unmodified &&
852+
test_when_finished "rm -f 000?-*" &&
853+
git format-patch --range-diff=$prev --notes=custom \
854+
--no-range-diff-notes --cover-letter \
855+
main..unmodified >actual &&
856+
test_grep "^Notes (custom):" 0004-* &&
857+
test_grep "^Range-diff:" 0000-cover-letter* &&
858+
test_grep ! "## Notes (custom) ##" 0000-cover-letter*
859+
'
860+
861+
test_expect_success 'format-patch --range-diff --range-diff-notes uses --notes behavior' '
862+
test_when_finished "git notes --ref=custom remove topic unmodified || :" &&
863+
git notes --ref=custom add -m "topic note1" topic &&
864+
git notes --ref=custom add -m "unmodified note1" unmodified &&
865+
test_when_finished "rm -f 000?-*" &&
866+
git format-patch --range-diff=$prev --notes=custom \
867+
--range-diff-notes --cover-letter \
868+
main..unmodified >actual &&
869+
test_grep "^Notes (custom):" 0004-* &&
870+
test_grep "^Range-diff:" 0000-cover-letter* &&
871+
test_grep "## Notes (custom) ##" 0000-cover-letter*
872+
'
873+
874+
test_expect_success 'format-patch --range-diff --notes=patch --range-diff-notes=rdiff' '
875+
test_when_finished "git notes --ref=patch remove topic unmodified || :" &&
876+
git notes --ref=patch add -m "only for patch 1" topic &&
877+
git notes --ref=patch add -m "only for patch 2" unmodified &&
878+
test_when_finished "git notes --ref=rdiff remove topic unmodified || :" &&
879+
git notes --ref=rdiff add -m "only for range diff 1" topic &&
880+
git notes --ref=rdiff add -m "only for range diff 2" unmodified &&
881+
test_when_finished "rm -f 000?-*" &&
882+
git format-patch --range-diff=$prev --notes=patch \
883+
--range-diff-notes=rdiff --cover-letter \
884+
main..unmodified >actual &&
885+
test_grep "^Notes (patch):" 0004-* &&
886+
test_grep ! "^Notes (rdiff):" 0004-* &&
887+
test_grep "^Range-diff:" 0000-cover-letter* &&
888+
test_grep "## Notes (rdiff) ##" 0000-cover-letter* &&
889+
test_grep ! "## Notes (patch) ##" 0000-cover-letter*
890+
'
891+
892+
test_expect_success 'format-patch --range-diff --no-range-diff-notes --range-diff-notes uses --notes behavior' '
893+
test_when_finished "git notes --ref=custom remove topic unmodified || :" &&
894+
git notes --ref=custom add -m "topic note1" topic &&
895+
git notes --ref=custom add -m "unmodified note1" unmodified &&
896+
test_when_finished "rm -f 000?-*" &&
897+
git format-patch --range-diff=$prev --notes=custom \
898+
--no-range-diff-notes --range-diff-notes --cover-letter \
899+
main..unmodified >actual &&
900+
test_grep "^Notes (custom):" 0004-* &&
901+
test_grep "^Range-diff:" 0000-cover-letter* &&
902+
test_grep "## Notes (custom) ##" 0000-cover-letter*
903+
'
904+
905+
test_expect_success 'format-patch --range-diff --range-diff-notes uses --notes behavior' '
906+
test_when_finished "git notes --ref=custom remove topic unmodified || :" &&
907+
git notes --ref=custom add -m "topic note1" topic &&
908+
git notes --ref=custom add -m "unmodified note1" unmodified &&
909+
test_when_finished "rm -f 000?-*" &&
910+
git format-patch --range-diff=$prev --notes=custom \
911+
--range-diff-notes --cover-letter \
912+
main..unmodified >actual &&
913+
test_grep "^Notes (custom):" 0004-* &&
914+
test_grep "^Range-diff:" 0000-cover-letter* &&
915+
test_grep "## Notes (custom) ##" 0000-cover-letter*
916+
'
917+
918+
test_expect_success 'format-patch --range-diff --no-range-diff-notes does not use default notes' '
919+
test_when_finished "git notes remove topic unmodified || :" &&
920+
git notes add -m "topic note1" topic &&
921+
git notes add -m "unmodified note1" unmodified &&
922+
test_when_finished "rm -f 000?-*" &&
923+
git format-patch --range-diff=$prev \
924+
--no-range-diff-notes --cover-letter \
925+
main..unmodified >actual &&
926+
test_grep ! "^Notes:" 0004-* &&
927+
test_grep "^Range-diff:" 0000-cover-letter* &&
928+
test_grep ! "## Notes ##" 0000-cover-letter*
929+
'
930+
931+
test_expect_success 'format-patch --range-diff --no-range-diff-notes on single patch' '
932+
test_when_finished "git notes --ref=custom remove HEAD unmodified || :" &&
933+
git notes --ref=custom add -m "topic note (custom)" HEAD &&
934+
git notes --ref=custom add -m "unmodified note (custom)" unmodified &&
935+
git format-patch --notes=custom --range-diff=$prev \
936+
--no-range-diff-notes -1 --stdout >actual &&
937+
test_grep "Notes (custom):" actual &&
938+
test_grep "^Range-diff:" actual &&
939+
test_grep ! "## Notes (custom) ##" actual
940+
'
941+
942+
test_expect_success 'format-patch --range-diff --range-diff-notes=custom on single patch' '
943+
test_when_finished "git notes --ref=custom remove HEAD unmodified || :" &&
944+
git notes --ref=custom add -m "topic note (custom)" HEAD &&
945+
git notes --ref=custom add -m "unmodified note (custom)" unmodified &&
946+
git format-patch --no-notes --range-diff=$prev \
947+
--range-diff-notes=custom -1 --stdout >actual &&
948+
test_grep ! "Notes (custom):" actual &&
949+
test_grep "^Range-diff:" actual &&
950+
test_grep "## Notes (custom) ##" actual
951+
'
952+
848953
test_expect_success '--left-only/--right-only' '
849954
git switch --orphan left-right &&
850955
test_commit first &&

0 commit comments

Comments
 (0)