Skip to content

Commit e06aae4

Browse files
committed
Merge branch 'kh/format-patch-range-diff-notes' into next
"git format-patch --range-diff=... --notes=..." did not drive the underlying range-diff with correct --notes parameter, ending up comparing with different set of notes from its main patch output you would get from "git format-patch --notes=..." for a singleton patch. * kh/format-patch-range-diff-notes: format-patch: handle range-diff on notes correctly for single patches revision: add rdiff_log_arg to rev_info range-diff: rename other_arg to log_arg
2 parents 5bc21d0 + 155986b commit e06aae4

File tree

7 files changed

+36
-20
lines changed

7 files changed

+36
-20
lines changed

builtin/log.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,23 +1406,20 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
14061406
* can be added later if deemed desirable.
14071407
*/
14081408
struct diff_options opts;
1409-
struct strvec other_arg = STRVEC_INIT;
14101409
struct range_diff_options range_diff_opts = {
14111410
.creation_factor = rev->creation_factor,
14121411
.dual_color = 1,
14131412
.max_memory = RANGE_DIFF_MAX_MEMORY_DEFAULT,
14141413
.diffopt = &opts,
1415-
.other_arg = &other_arg
1414+
.log_arg = &rev->rdiff_log_arg
14161415
};
14171416

14181417
repo_diff_setup(the_repository, &opts);
14191418
opts.file = rev->diffopt.file;
14201419
opts.use_color = rev->diffopt.use_color;
14211420
diff_setup_done(&opts);
14221421
fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
1423-
get_notes_args(&other_arg, rev);
14241422
show_range_diff(rev->rdiff1, rev->rdiff2, &range_diff_opts);
1425-
strvec_clear(&other_arg);
14261423
}
14271424
}
14281425

@@ -2334,6 +2331,7 @@ int cmd_format_patch(int argc,
23342331
rev.rdiff_title = diff_title(&rdiff_title, reroll_count,
23352332
_("Range-diff:"),
23362333
_("Range-diff against v%d:"));
2334+
get_notes_args(&(rev.rdiff_log_arg), &rev);
23372335
}
23382336

23392337
/*
@@ -2493,6 +2491,7 @@ int cmd_format_patch(int argc,
24932491
rev.diffopt.no_free = 0;
24942492
release_revisions(&rev);
24952493
format_config_release(&cfg);
2494+
strvec_clear(&rev.rdiff_log_arg);
24962495
return 0;
24972496
}
24982497

builtin/range-diff.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ int cmd_range_diff(int argc,
3838
struct repository *repo UNUSED)
3939
{
4040
struct diff_options diffopt = { NULL };
41-
struct strvec other_arg = STRVEC_INIT;
41+
struct strvec log_arg = STRVEC_INIT;
4242
struct strvec diff_merges_arg = STRVEC_INIT;
4343
struct range_diff_options range_diff_opts = {
4444
.creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT,
4545
.max_memory = RANGE_DIFF_MAX_MEMORY_DEFAULT,
4646
.diffopt = &diffopt,
47-
.other_arg = &other_arg
47+
.log_arg = &log_arg
4848
};
4949
int simple_color = -1, left_only = 0, right_only = 0;
5050
struct option range_diff_options[] = {
@@ -53,7 +53,7 @@ int cmd_range_diff(int argc,
5353
N_("percentage by which creation is weighted")),
5454
OPT_BOOL(0, "no-dual-color", &simple_color,
5555
N_("use simple diff colors")),
56-
OPT_PASSTHRU_ARGV(0, "notes", &other_arg,
56+
OPT_PASSTHRU_ARGV(0, "notes", &log_arg,
5757
N_("notes"), N_("passed to 'git log'"),
5858
PARSE_OPT_OPTARG),
5959
OPT_PASSTHRU_ARGV(0, "diff-merges", &diff_merges_arg,
@@ -93,7 +93,7 @@ int cmd_range_diff(int argc,
9393
/* If `--diff-merges` was specified, imply `--merges` */
9494
if (diff_merges_arg.nr) {
9595
range_diff_opts.include_merges = 1;
96-
strvec_pushv(&other_arg, diff_merges_arg.v);
96+
strvec_pushv(&log_arg, diff_merges_arg.v);
9797
}
9898

9999
for (i = 0; i < argc; i++)
@@ -125,7 +125,7 @@ int cmd_range_diff(int argc,
125125
strbuf_addf(&range1, "%s..%s", argv[0], argv[1]);
126126
strbuf_addf(&range2, "%s..%s", argv[0], argv[2]);
127127

128-
strvec_pushv(&other_arg, argv +
128+
strvec_pushv(&log_arg, argv +
129129
(dash_dash < 0 ? 3 : dash_dash));
130130
} else if (dash_dash == 2 ||
131131
(dash_dash < 0 && argc > 1 &&
@@ -145,7 +145,7 @@ int cmd_range_diff(int argc,
145145
strbuf_addstr(&range1, argv[0]);
146146
strbuf_addstr(&range2, argv[1]);
147147

148-
strvec_pushv(&other_arg, argv +
148+
strvec_pushv(&log_arg, argv +
149149
(dash_dash < 0 ? 2 : dash_dash));
150150
} else if (dash_dash == 1 ||
151151
(dash_dash < 0 && argc > 0 &&
@@ -176,7 +176,7 @@ int cmd_range_diff(int argc,
176176
strbuf_addf(&range1, "%s..%.*s", b, a_len, a);
177177
strbuf_addf(&range2, "%.*s..%s", a_len, a, b);
178178

179-
strvec_pushv(&other_arg, argv +
179+
strvec_pushv(&log_arg, argv +
180180
(dash_dash < 0 ? 1 : dash_dash));
181181
} else
182182
usage_msg_opt(_("need two commit ranges"),
@@ -188,7 +188,7 @@ int cmd_range_diff(int argc,
188188
range_diff_opts.right_only = right_only;
189189
res = show_range_diff(range1.buf, range2.buf, &range_diff_opts);
190190

191-
strvec_clear(&other_arg);
191+
strvec_clear(&log_arg);
192192
strvec_clear(&diff_merges_arg);
193193
strbuf_release(&range1);
194194
strbuf_release(&range2);

log-tree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,8 @@ static void show_diff_of_diff(struct rev_info *opt)
718718
.creation_factor = opt->creation_factor,
719719
.dual_color = 1,
720720
.max_memory = RANGE_DIFF_MAX_MEMORY_DEFAULT,
721-
.diffopt = &opts
721+
.diffopt = &opts,
722+
.log_arg = &opt->rdiff_log_arg
722723
};
723724

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

range-diff.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct patch_util {
3939
* as struct object_id (will need to be free()d).
4040
*/
4141
static int read_patches(const char *range, struct string_list *list,
42-
const struct strvec *other_arg,
42+
const struct strvec *log_arg,
4343
unsigned int include_merges)
4444
{
4545
struct child_process cp = CHILD_PROCESS_INIT;
@@ -69,8 +69,8 @@ static int read_patches(const char *range, struct string_list *list,
6969
if (!include_merges)
7070
strvec_push(&cp.args, "--no-merges");
7171
strvec_push(&cp.args, range);
72-
if (other_arg)
73-
strvec_pushv(&cp.args, other_arg->v);
72+
if (log_arg)
73+
strvec_pushv(&cp.args, log_arg->v);
7474
cp.out = -1;
7575
cp.no_stdin = 1;
7676
cp.git_cmd = 1;
@@ -594,9 +594,9 @@ int show_range_diff(const char *range1, const char *range2,
594594
if (range_diff_opts->left_only && range_diff_opts->right_only)
595595
res = error(_("options '%s' and '%s' cannot be used together"), "--left-only", "--right-only");
596596

597-
if (!res && read_patches(range1, &branch1, range_diff_opts->other_arg, include_merges))
597+
if (!res && read_patches(range1, &branch1, range_diff_opts->log_arg, include_merges))
598598
res = error(_("could not parse log for '%s'"), range1);
599-
if (!res && read_patches(range2, &branch2, range_diff_opts->other_arg, include_merges))
599+
if (!res && read_patches(range2, &branch2, range_diff_opts->log_arg, include_merges))
600600
res = error(_("could not parse log for '%s'"), range2);
601601

602602
if (!res) {

range-diff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct range_diff_options {
2323
unsigned include_merges:1;
2424
size_t max_memory;
2525
const struct diff_options *diffopt; /* may be NULL */
26-
const struct strvec *other_arg; /* may be NULL */
26+
const struct strvec *log_arg; /* may be NULL */
2727
};
2828

2929
/*

revision.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ struct rev_info {
334334
/* range-diff */
335335
const char *rdiff1;
336336
const char *rdiff2;
337+
struct strvec rdiff_log_arg;
337338
int creation_factor;
338339
const char *rdiff_title;
339340

@@ -410,6 +411,7 @@ struct rev_info {
410411
.expand_tabs_in_log = -1, \
411412
.commit_format = CMIT_FMT_DEFAULT, \
412413
.expand_tabs_in_log_default = 8, \
414+
.rdiff_log_arg = STRVEC_INIT, \
413415
}
414416

415417
/**

t/t3206-range-diff.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ test_expect_success 'format-patch --range-diff does not compare notes by default
707707
! grep "note" 0000-*
708708
'
709709

710-
test_expect_success 'format-patch --notes=custom --range-diff only compares custom notes' '
710+
test_expect_success 'format-patch --notes=custom --range-diff --cover-letter only compares custom notes' '
711711
test_when_finished "git notes remove topic unmodified || :" &&
712712
git notes add -m "topic note" topic &&
713713
git notes add -m "unmodified note" unmodified &&
@@ -721,6 +721,20 @@ test_expect_success 'format-patch --notes=custom --range-diff only compares cust
721721
! grep "## Notes ##" 0000-*
722722
'
723723

724+
# --range-diff on a single commit requires --no-cover-letter
725+
test_expect_success 'format-patch --notes=custom --range-diff on single commit only compares custom notes' '
726+
test_when_finished "git notes remove HEAD unmodified || :" &&
727+
git notes add -m "topic note" HEAD &&
728+
test_when_finished "git notes --ref=custom remove HEAD unmodified || :" &&
729+
git notes add -m "unmodified note" unmodified &&
730+
git notes --ref=custom add -m "topic note (custom)" HEAD &&
731+
git notes --ref=custom add -m "unmodified note (custom)" unmodified &&
732+
git format-patch --notes=custom --range-diff=$prev \
733+
-1 --stdout >actual &&
734+
test_grep "## Notes (custom) ##" actual &&
735+
test_grep ! "## Notes ##" actual
736+
'
737+
724738
test_expect_success 'format-patch --range-diff with --no-notes' '
725739
test_when_finished "git notes remove topic unmodified || :" &&
726740
git notes add -m "topic note" topic &&

0 commit comments

Comments
 (0)