diff-parseopt: convert --word-diff-regex

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 797df119a2aa7cc1f1b69851e9eae26eeb17bc14
1 file changed +15 -6
diff.c
+15 -6
@@ -5092,6 +5092,18 @@ static int diff_opt_word_diff(const struct option *opt,
5092 return 0;
5093 }
5094
5095 +static int diff_opt_word_diff_regex(const struct option *opt,
5096 + const char *arg, int unset)
5097 +{
5098 + struct diff_options *options = opt->value;
5099 +
5100 + BUG_ON_OPT_NEG(unset);
5101 + if (options->word_diff == DIFF_WORDS_NONE)
5102 + options->word_diff = DIFF_WORDS_PLAIN;
5103 + options->word_regex = arg;
5104 + return 0;
5105 +}
5106 +
5107 static void prep_parse_options(struct diff_options *options)
5108 {
5109 struct option parseopts[] = {
@@ -5257,6 +5269,9 @@ static void prep_parse_options(struct diff_options *options)
5269 OPT_CALLBACK_F(0, "word-diff", options, N_("<mode>"),
5270 N_("show word diff, using <mode> to delimit changed words"),
5271 PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_word_diff),
5272 + OPT_CALLBACK_F(0, "word-diff-regex", options, N_("<regex>"),
5273 + N_("use <regex> to decide what a word is"),
5274 + PARSE_OPT_NONEG, diff_opt_word_diff_regex),
5275
5276 OPT_GROUP(N_("Diff other options")),
5277 OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5320,12 +5335,6 @@ int diff_opt_parse(struct diff_options *options,
5335 options->use_color = 1;
5336 options->word_diff = DIFF_WORDS_COLOR;
5337 }
5323 - else if ((argcount = parse_long_opt("word-diff-regex", av, &optarg))) {
5324 - if (options->word_diff == DIFF_WORDS_NONE)
5325 - options->word_diff = DIFF_WORDS_PLAIN;
5326 - options->word_regex = optarg;
5327 - return argcount;
5328 - }
5338 else if (!strcmp(arg, "--exit-code"))
5339 options->flags.exit_with_status = 1;
5340 else if (!strcmp(arg, "--quiet"))