diff options
Diffstat (limited to 'builtin/range-diff.c')
| -rw-r--r-- | builtin/range-diff.c | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/builtin/range-diff.c b/builtin/range-diff.c index 1b33ab66a7..e54c0f7fe1 100644 --- a/builtin/range-diff.c +++ b/builtin/range-diff.c @@ -1,10 +1,13 @@ #define USE_THE_REPOSITORY_VARIABLE + #include "builtin.h" #include "gettext.h" #include "object-name.h" #include "parse-options.h" #include "range-diff.h" #include "config.h" +#include "parse.h" +#include "color.h" static const char * const builtin_range_diff_usage[] = { @@ -14,17 +17,34 @@ N_("git range-diff [<options>] <base> <old-tip> <new-tip>"), NULL }; +static int parse_max_memory(const struct option *opt, const char *arg, int unset) +{ + size_t *max_memory = opt->value; + uintmax_t val; + + if (unset) + return 0; + + if (!git_parse_unsigned(arg, &val, SIZE_MAX)) + return error(_("invalid max-memory value: %s"), arg); + + *max_memory = (size_t)val; + return 0; +} + int cmd_range_diff(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) { struct diff_options diffopt = { NULL }; - struct strvec other_arg = STRVEC_INIT; + struct strvec log_arg = STRVEC_INIT; + struct strvec diff_merges_arg = STRVEC_INIT; struct range_diff_options range_diff_opts = { .creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT, + .max_memory = RANGE_DIFF_MAX_MEMORY_DEFAULT, .diffopt = &diffopt, - .other_arg = &other_arg + .log_arg = &log_arg }; int simple_color = -1, left_only = 0, right_only = 0; struct option range_diff_options[] = { @@ -33,9 +53,17 @@ int cmd_range_diff(int argc, 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, + OPT_PASSTHRU_ARGV(0, "notes", &log_arg, N_("notes"), N_("passed to 'git log'"), PARSE_OPT_OPTARG), + OPT_PASSTHRU_ARGV(0, "diff-merges", &diff_merges_arg, + N_("style"), N_("passed to 'git log'"), 0), + OPT_CALLBACK(0, "max-memory", &range_diff_opts.max_memory, + N_("size"), + N_("maximum memory for cost matrix (default 4G)"), + parse_max_memory), + OPT_PASSTHRU_ARGV(0, "remerge-diff", &diff_merges_arg, NULL, + N_("passed to 'git log'"), PARSE_OPT_NOARG), OPT_BOOL(0, "left-only", &left_only, N_("only emit output related to the first range")), OPT_BOOL(0, "right-only", &right_only, @@ -48,7 +76,7 @@ int cmd_range_diff(int argc, struct object_id oid; const char *three_dots = NULL; - git_config(git_diff_ui_config, NULL); + repo_config(the_repository, git_diff_ui_config, NULL); repo_diff_setup(the_repository, &diffopt); @@ -60,7 +88,13 @@ int cmd_range_diff(int argc, /* force color when --dual-color was used */ if (!simple_color) - diffopt.use_color = 1; + diffopt.use_color = GIT_COLOR_ALWAYS; + + /* If `--diff-merges` was specified, imply `--merges` */ + if (diff_merges_arg.nr) { + range_diff_opts.include_merges = 1; + strvec_pushv(&log_arg, diff_merges_arg.v); + } for (i = 0; i < argc; i++) if (!strcmp(argv[i], "--")) { @@ -91,7 +125,7 @@ int cmd_range_diff(int argc, strbuf_addf(&range1, "%s..%s", argv[0], argv[1]); strbuf_addf(&range2, "%s..%s", argv[0], argv[2]); - strvec_pushv(&other_arg, argv + + strvec_pushv(&log_arg, argv + (dash_dash < 0 ? 3 : dash_dash)); } else if (dash_dash == 2 || (dash_dash < 0 && argc > 1 && @@ -111,7 +145,7 @@ int cmd_range_diff(int argc, strbuf_addstr(&range1, argv[0]); strbuf_addstr(&range2, argv[1]); - strvec_pushv(&other_arg, argv + + strvec_pushv(&log_arg, argv + (dash_dash < 0 ? 2 : dash_dash)); } else if (dash_dash == 1 || (dash_dash < 0 && argc > 0 && @@ -142,7 +176,7 @@ int cmd_range_diff(int argc, strbuf_addf(&range1, "%s..%.*s", b, a_len, a); strbuf_addf(&range2, "%.*s..%s", a_len, a, b); - strvec_pushv(&other_arg, argv + + strvec_pushv(&log_arg, argv + (dash_dash < 0 ? 1 : dash_dash)); } else usage_msg_opt(_("need two commit ranges"), @@ -154,7 +188,8 @@ int cmd_range_diff(int argc, range_diff_opts.right_only = right_only; res = show_range_diff(range1.buf, range2.buf, &range_diff_opts); - strvec_clear(&other_arg); + strvec_clear(&log_arg); + strvec_clear(&diff_merges_arg); strbuf_release(&range1); strbuf_release(&range2); |
