Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- diff.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/diff.c b/diff.c index cc10b27df0..5403351466 100644 --- a/diff.c +++ b/diff.c @@ -4905,6 +4905,27 @@ static int diff_opt_char(const struct option *opt, return 0; } +static int diff_opt_color_moved(const struct option *opt, + const char *arg, int unset) +{ + struct diff_options *options = opt->value; + + if (unset) { + options->color_moved = COLOR_MOVED_NO; + } else if (!arg) { + if (diff_color_moved_default) + options->color_moved = diff_color_moved_default; + if (options->color_moved == COLOR_MOVED_NO) + options->color_moved = COLOR_MOVED_DEFAULT; + } else { + int cm = parse_color_moved(arg); + if (cm < 0) + return error("bad --color-moved argument: %s", arg); + options->color_moved = cm; + } + return 0; +} + static int diff_opt_color_words(const struct option *opt, const char *arg, int unset) { @@ -5403,6 +5424,9 @@ static void prep_parse_options(struct diff_options *options) OPT_CALLBACK_F(0, "color-words", options, N_("<regex>"), N_("equivalent to --word-diff=color --word-diff-regex=<regex>"), PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_color_words), + OPT_CALLBACK_F(0, "color-moved", options, N_("<mode>"), + N_("move lines of code are colored differently"), + PARSE_OPT_OPTARG, diff_opt_color_moved), OPT_GROUP(N_("Diff other options")), OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"), @@ -5486,19 +5510,7 @@ int diff_opt_parse(struct diff_options *options, return ac; /* flags options */ - if (!strcmp(arg, "--color-moved")) { - if (diff_color_moved_default) - options->color_moved = diff_color_moved_default; - if (options->color_moved == COLOR_MOVED_NO) - options->color_moved = COLOR_MOVED_DEFAULT; - } else if (!strcmp(arg, "--no-color-moved")) - options->color_moved = COLOR_MOVED_NO; - else if (skip_prefix(arg, "--color-moved=", &arg)) { - int cm = parse_color_moved(arg); - if (cm < 0) - return error("bad --color-moved argument: %s", arg); - options->color_moved = cm; - } else if (skip_prefix(arg, "--color-moved-ws=", &arg)) { + if (skip_prefix(arg, "--color-moved-ws=", &arg)) { unsigned cm = parse_color_moved_ws(arg); if (cm & COLOR_MOVED_WS_ERROR) return -1; -- 2.20.0.482.g66447595a7