diff-parseopt: convert --color-moved-ws

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 24, 2019 at 15:20 UTC 8ce2020ff079955b4a068d96a93e00a65f570355
1 file changed +18 -17
diff.c
+18 -17
@@ -4862,6 +4862,20 @@ static int diff_opt_color_moved(const struct option *opt,
4862 return 0;
4863 }
4864
4865 +static int diff_opt_color_moved_ws(const struct option *opt,
4866 + const char *arg, int unset)
4867 +{
4868 + struct diff_options *options = opt->value;
4869 + unsigned cm;
4870 +
4871 + BUG_ON_OPT_NEG(unset);
4872 + cm = parse_color_moved_ws(arg);
4873 + if (cm & COLOR_MOVED_WS_ERROR)
4874 + return error(_("invalid mode '%s' in --color-moved-ws"), arg);
4875 + options->color_moved_ws_handling = cm;
4876 + return 0;
4877 +}
4878 +
4879 static int diff_opt_color_words(const struct option *opt,
4880 const char *arg, int unset)
4881 {
@@ -5363,6 +5377,9 @@ static void prep_parse_options(struct diff_options *options)
5377 OPT_CALLBACK_F(0, "color-moved", options, N_("<mode>"),
5378 N_("move lines of code are colored differently"),
5379 PARSE_OPT_OPTARG, diff_opt_color_moved),
5380 + OPT_CALLBACK_F(0, "color-moved-ws", options, N_("<mode>"),
5381 + N_("how white spaces are ignored in --color-moved"),
5382 + PARSE_OPT_NONEG, diff_opt_color_moved_ws),
5383
5384 OPT_GROUP(N_("Diff other options")),
5385 OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5430,8 +5447,6 @@ static void prep_parse_options(struct diff_options *options)
5447 int diff_opt_parse(struct diff_options *options,
5448 const char **av, int ac, const char *prefix)
5449 {
5433 - const char *arg = av[0];
5434 -
5450 if (!prefix)
5451 prefix = "";
5452
@@ -5442,21 +5457,7 @@ int diff_opt_parse(struct diff_options *options,
5457 PARSE_OPT_ONE_SHOT |
5458 PARSE_OPT_STOP_AT_NON_OPTION);
5459
5445 - if (ac)
5446 - return ac;
5447 -
5448 - /* flags options */
5449 - if (skip_prefix(arg, "--color-moved-ws=", &arg)) {
5450 - unsigned cm = parse_color_moved_ws(arg);
5451 - if (cm & COLOR_MOVED_WS_ERROR)
5452 - return -1;
5453 - options->color_moved_ws_handling = cm;
5454 - }
5455 -
5456 - /* misc options */
5457 - else
5458 - return 0;
5459 - return 1;
5460 + return ac;
5461 }
5462
5463 int parse_rename_score(const char **cp_p)