summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2021-02-18 01:21:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-02-18 01:21:41 (GMT)
commitdadc91ff0c15b655070ad334a27a734e91635bd5 (patch)
treec53f828a0941fae682ee087bd21e935de607e2e5 /builtin
parent77348b0e6e350ec81b3880f99c6077d165df2276 (diff)
parent1e79f973266cfe0e3bab0e26e869b682078e457d (diff)
downloadgit-dadc91ff0c15b655070ad334a27a734e91635bd5.zip
git-dadc91ff0c15b655070ad334a27a734e91635bd5.tar.gz
git-dadc91ff0c15b655070ad334a27a734e91635bd5.tar.bz2
Merge branch 'js/range-diff-one-side-only'
The "git range-diff" command learned "--(left|right)-only" option to show only one side of the compared range. * js/range-diff-one-side-only: range-diff: offer --left-only/--right-only options range-diff: move the diffopt initialization down one layer range-diff: combine all options in a single data structure range-diff: simplify code spawning `git log` range-diff: libify the read_patches() function again range-diff: avoid leaking memory in two error code paths
Diffstat (limited to 'builtin')
-rw-r--r--builtin/log.c10
-rw-r--r--builtin/range-diff.c21
2 files changed, 24 insertions, 7 deletions
diff --git a/builtin/log.c b/builtin/log.c
index a00da91..be29c3f 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1223,14 +1223,20 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
*/
struct diff_options opts;
struct strvec other_arg = STRVEC_INIT;
+ struct range_diff_options range_diff_opts = {
+ .creation_factor = rev->creation_factor,
+ .dual_color = 1,
+ .diffopt = &opts,
+ .other_arg = &other_arg
+ };
+
diff_setup(&opts);
opts.file = rev->diffopt.file;
opts.use_color = rev->diffopt.use_color;
diff_setup_done(&opts);
fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
get_notes_args(&other_arg, rev);
- show_range_diff(rev->rdiff1, rev->rdiff2,
- rev->creation_factor, 1, &opts, &other_arg);
+ show_range_diff(rev->rdiff1, rev->rdiff2, &range_diff_opts);
strvec_clear(&other_arg);
}
}
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
index 5b1f632..78bc9fa 100644
--- a/builtin/range-diff.c
+++ b/builtin/range-diff.c
@@ -14,18 +14,27 @@ NULL
int cmd_range_diff(int argc, const char **argv, const char *prefix)
{
- int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
struct diff_options diffopt = { NULL };
struct strvec other_arg = STRVEC_INIT;
- int simple_color = -1;
+ struct range_diff_options range_diff_opts = {
+ .creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT,
+ .diffopt = &diffopt,
+ .other_arg = &other_arg
+ };
+ int simple_color = -1, left_only = 0, right_only = 0;
struct option range_diff_options[] = {
- OPT_INTEGER(0, "creation-factor", &creation_factor,
+ OPT_INTEGER(0, "creation-factor",
+ &range_diff_opts.creation_factor,
N_("Percentage by which creation is weighted")),
OPT_BOOL(0, "no-dual-color", &simple_color,
N_("use simple diff colors")),
OPT_PASSTHRU_ARGV(0, "notes", &other_arg,
N_("notes"), N_("passed to 'git log'"),
PARSE_OPT_OPTARG),
+ OPT_BOOL(0, "left-only", &left_only,
+ N_("only emit output related to the first range")),
+ OPT_BOOL(0, "right-only", &right_only,
+ N_("only emit output related to the second range")),
OPT_END()
};
struct option *options;
@@ -82,8 +91,10 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
}
FREE_AND_NULL(options);
- res = show_range_diff(range1.buf, range2.buf, creation_factor,
- simple_color < 1, &diffopt, &other_arg);
+ range_diff_opts.dual_color = simple_color < 1;
+ range_diff_opts.left_only = left_only;
+ range_diff_opts.right_only = right_only;
+ res = show_range_diff(range1.buf, range2.buf, &range_diff_opts);
strvec_clear(&other_arg);
strbuf_release(&range1);