diff-parseopt: convert --color-words

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Mar 5, 2019 at 19:30 UTC 212db69d8c768413ff26f8665e14beef7445e8d7
1 file changed +16 -5
diff.c
+16 -5
@@ -4901,6 +4901,18 @@ static int diff_opt_char(const struct option *opt,
4901 return 0;
4902 }
4903
4904 +static int diff_opt_color_words(const struct option *opt,
4905 + const char *arg, int unset)
4906 +{
4907 + struct diff_options *options = opt->value;
4908 +
4909 + BUG_ON_OPT_NEG(unset);
4910 + options->use_color = 1;
4911 + options->word_diff = DIFF_WORDS_COLOR;
4912 + options->word_regex = arg;
4913 + return 0;
4914 +}
4915 +
4916 static int diff_opt_compact_summary(const struct option *opt,
4917 const char *arg, int unset)
4918 {
@@ -5272,6 +5284,9 @@ static void prep_parse_options(struct diff_options *options)
5284 OPT_CALLBACK_F(0, "word-diff-regex", options, N_("<regex>"),
5285 N_("use <regex> to decide what a word is"),
5286 PARSE_OPT_NONEG, diff_opt_word_diff_regex),
5287 + OPT_CALLBACK_F(0, "color-words", options, N_("<regex>"),
5288 + N_("equivalent to --word-diff=color --word-diff-regex=<regex>"),
5289 + PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_color_words),
5290
5291 OPT_GROUP(N_("Diff other options")),
5292 OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5331,11 +5346,7 @@ int diff_opt_parse(struct diff_options *options,
5346 if (cm & COLOR_MOVED_WS_ERROR)
5347 return -1;
5348 options->color_moved_ws_handling = cm;
5334 - } else if (skip_to_optional_arg_default(arg, "--color-words", &options->word_regex, NULL)) {
5335 - options->use_color = 1;
5336 - options->word_diff = DIFF_WORDS_COLOR;
5337 - }
5338 - else if (!strcmp(arg, "--exit-code"))
5349 + } else if (!strcmp(arg, "--exit-code"))
5350 options->flags.exit_with_status = 1;
5351 else if (!strcmp(arg, "--quiet"))
5352 options->flags.quick = 1;