Skip to content

Commit f1ce6c1

Browse files
dschogitster
authored andcommitted
range-diff: combine all options in a single data structure
This will make it easier to implement the `--left-only` and `--right-only` options. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5189bb8 commit f1ce6c1

File tree

5 files changed

+42
-23
lines changed

5 files changed

+42
-23
lines changed

builtin/log.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,14 +1231,20 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
12311231
*/
12321232
struct diff_options opts;
12331233
struct strvec other_arg = STRVEC_INIT;
1234+
struct range_diff_options range_diff_opts = {
1235+
.creation_factor = rev->creation_factor,
1236+
.dual_color = 1,
1237+
.diffopt = &opts,
1238+
.other_arg = &other_arg
1239+
};
1240+
12341241
diff_setup(&opts);
12351242
opts.file = rev->diffopt.file;
12361243
opts.use_color = rev->diffopt.use_color;
12371244
diff_setup_done(&opts);
12381245
fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
12391246
get_notes_args(&other_arg, rev);
1240-
show_range_diff(rev->rdiff1, rev->rdiff2,
1241-
rev->creation_factor, 1, &opts, &other_arg);
1247+
show_range_diff(rev->rdiff1, rev->rdiff2, &range_diff_opts);
12421248
strvec_clear(&other_arg);
12431249
}
12441250
}

builtin/range-diff.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ NULL
1313

1414
int cmd_range_diff(int argc, const char **argv, const char *prefix)
1515
{
16-
int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
1716
struct diff_options diffopt = { NULL };
1817
struct strvec other_arg = STRVEC_INIT;
18+
struct range_diff_options range_diff_opts = {
19+
.creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT,
20+
.diffopt = &diffopt,
21+
.other_arg = &other_arg
22+
};
1923
int simple_color = -1;
2024
struct option range_diff_options[] = {
21-
OPT_INTEGER(0, "creation-factor", &creation_factor,
25+
OPT_INTEGER(0, "creation-factor",
26+
&range_diff_opts.creation_factor,
2227
N_("Percentage by which creation is weighted")),
2328
OPT_BOOL(0, "no-dual-color", &simple_color,
2429
N_("use simple diff colors")),
@@ -81,8 +86,8 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
8186
}
8287
FREE_AND_NULL(options);
8388

84-
res = show_range_diff(range1.buf, range2.buf, creation_factor,
85-
simple_color < 1, &diffopt, &other_arg);
89+
range_diff_opts.dual_color = simple_color < 1;
90+
res = show_range_diff(range1.buf, range2.buf, &range_diff_opts);
8691

8792
strvec_clear(&other_arg);
8893
strbuf_release(&range1);

log-tree.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,11 @@ void show_log(struct rev_info *opt)
808808
if (cmit_fmt_is_mail(ctx.fmt) && opt->rdiff1) {
809809
struct diff_queue_struct dq;
810810
struct diff_options opts;
811+
struct range_diff_options range_diff_opts = {
812+
.creation_factor = opt->creation_factor,
813+
.dual_color = 1,
814+
.diffopt = &opts
815+
};
811816

812817
memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
813818
DIFF_QUEUE_CLEAR(&diff_queued_diff);
@@ -822,8 +827,7 @@ void show_log(struct rev_info *opt)
822827
opts.file = opt->diffopt.file;
823828
opts.use_color = opt->diffopt.use_color;
824829
diff_setup_done(&opts);
825-
show_range_diff(opt->rdiff1, opt->rdiff2,
826-
opt->creation_factor, 1, &opts, NULL);
830+
show_range_diff(opt->rdiff1, opt->rdiff2, &range_diff_opts);
827831

828832
memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
829833
}

range-diff.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -525,41 +525,41 @@ static struct strbuf *output_prefix_cb(struct diff_options *opt, void *data)
525525
}
526526

527527
int show_range_diff(const char *range1, const char *range2,
528-
int creation_factor, int dual_color,
529-
const struct diff_options *diffopt,
530-
const struct strvec *other_arg)
528+
struct range_diff_options *range_diff_opts)
531529
{
532530
int res = 0;
533531

534532
struct string_list branch1 = STRING_LIST_INIT_DUP;
535533
struct string_list branch2 = STRING_LIST_INIT_DUP;
536534

537-
if (read_patches(range1, &branch1, other_arg))
535+
if (read_patches(range1, &branch1, range_diff_opts->other_arg))
538536
res = error(_("could not parse log for '%s'"), range1);
539-
if (!res && read_patches(range2, &branch2, other_arg))
537+
if (!res && read_patches(range2, &branch2, range_diff_opts->other_arg))
540538
res = error(_("could not parse log for '%s'"), range2);
541539

542540
if (!res) {
543541
struct diff_options opts;
544542
struct strbuf indent = STRBUF_INIT;
545543

546-
if (diffopt)
547-
memcpy(&opts, diffopt, sizeof(opts));
544+
if (range_diff_opts->diffopt)
545+
memcpy(&opts, range_diff_opts->diffopt, sizeof(opts));
548546
else
549547
diff_setup(&opts);
550548

551549
if (!opts.output_format)
552550
opts.output_format = DIFF_FORMAT_PATCH;
553551
opts.flags.suppress_diff_headers = 1;
554-
opts.flags.dual_color_diffed_diffs = dual_color;
552+
opts.flags.dual_color_diffed_diffs =
553+
range_diff_opts->dual_color;
555554
opts.flags.suppress_hunk_header_line_count = 1;
556555
opts.output_prefix = output_prefix_cb;
557556
strbuf_addstr(&indent, " ");
558557
opts.output_prefix_data = &indent;
559558
diff_setup_done(&opts);
560559

561560
find_exact_matches(&branch1, &branch2);
562-
get_correspondences(&branch1, &branch2, creation_factor);
561+
get_correspondences(&branch1, &branch2,
562+
range_diff_opts->creation_factor);
563563
output(&branch1, &branch2, &opts);
564564

565565
strbuf_release(&indent);

range-diff.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66

77
#define RANGE_DIFF_CREATION_FACTOR_DEFAULT 60
88

9+
struct range_diff_options {
10+
int creation_factor;
11+
unsigned dual_color:1;
12+
const struct diff_options *diffopt; /* may be NULL */
13+
const struct strvec *other_arg; /* may be NULL */
14+
};
15+
916
/*
10-
* Compare series of commits in RANGE1 and RANGE2, and emit to the
11-
* standard output. NULL can be passed to DIFFOPT to use the built-in
12-
* default.
17+
* Compare series of commits in `range1` and `range2`, and emit to the
18+
* standard output.
1319
*/
1420
int show_range_diff(const char *range1, const char *range2,
15-
int creation_factor, int dual_color,
16-
const struct diff_options *diffopt,
17-
const struct strvec *other_arg);
21+
struct range_diff_options *opts);
1822

1923
#endif

0 commit comments

Comments
 (0)