diff-parseopt: convert --relative

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 Feb 21, 2019 at 18:16 UTC 0b1c5b59f0507e428485c7d843c11d6085555db0
1 file changed +17 -8
diff.c
+17 -8
@@ -4960,6 +4960,18 @@ static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
4960 return 0;
4961 }
4962
4963 +static int diff_opt_relative(const struct option *opt,
4964 + const char *arg, int unset)
4965 +{
4966 + struct diff_options *options = opt->value;
4967 +
4968 + BUG_ON_OPT_NEG(unset);
4969 + options->flags.relative_name = 1;
4970 + if (arg)
4971 + options->prefix = arg;
4972 + return 0;
4973 +}
4974 +
4975 static int diff_opt_unified(const struct option *opt,
4976 const char *arg, int unset)
4977 {
@@ -5094,6 +5106,10 @@ static void prep_parse_options(struct diff_options *options)
5106 N_("use empty blobs as rename source")),
5107
5108 OPT_GROUP(N_("Diff other options")),
5109 + OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
5110 + N_("when run from subdir, exclude changes outside and show relative paths"),
5111 + PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
5112 + diff_opt_relative),
5113 { OPTION_CALLBACK, 0, "output", options, N_("<file>"),
5114 N_("Output to a specific file"),
5115 PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5125,15 +5141,8 @@ int diff_opt_parse(struct diff_options *options,
5141 if (ac)
5142 return ac;
5143
5128 - /* renames options */
5129 - if (skip_to_optional_arg_default(arg, "--relative", &arg, NULL)) {
5130 - options->flags.relative_name = 1;
5131 - if (arg)
5132 - options->prefix = arg;
5133 - }
5134 -
5144 /* xdiff options */
5136 - else if (!strcmp(arg, "--minimal"))
5145 + if (!strcmp(arg, "--minimal"))
5146 DIFF_XDL_SET(options, NEED_MINIMAL);
5147 else if (!strcmp(arg, "--no-minimal"))
5148 DIFF_XDL_CLR(options, NEED_MINIMAL);