diff-parseopt: convert --[no-]follow

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 1e9250b5aaf6e13b3e0b593147dcb8488c08f049
1 file changed +19 -6
diff.c
+19 -6
@@ -4986,6 +4986,21 @@ static int diff_opt_find_renames(const struct option *opt,
4986 return 0;
4987 }
4988
4989 +static int diff_opt_follow(const struct option *opt,
4990 + const char *arg, int unset)
4991 +{
4992 + struct diff_options *options = opt->value;
4993 +
4994 + BUG_ON_OPT_ARG(arg);
4995 + if (unset) {
4996 + options->flags.follow_renames = 0;
4997 + options->flags.default_follow_renames = 0;
4998 + } else {
4999 + options->flags.follow_renames = 1;
5000 + }
5001 + return 0;
5002 +}
5003 +
5004 static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
5005 const struct option *opt,
5006 const char *arg, int unset)
@@ -5172,6 +5187,9 @@ static void prep_parse_options(struct diff_options *options)
5187 0, PARSE_OPT_NONEG),
5188 OPT_BOOL(0, "rename-empty", &options->flags.rename_empty,
5189 N_("use empty blobs as rename source")),
5190 + OPT_CALLBACK_F(0, "follow", options, NULL,
5191 + N_("continue listing the history of a file beyond renames"),
5192 + PARSE_OPT_NOARG, diff_opt_follow),
5193
5194 OPT_GROUP(N_("Diff algorithm options")),
5195 OPT_BIT(0, "minimal", &options->xdl_opts,
@@ -5250,12 +5268,7 @@ int diff_opt_parse(struct diff_options *options,
5268 return ac;
5269
5270 /* flags options */
5253 - if (!strcmp(arg, "--follow"))
5254 - options->flags.follow_renames = 1;
5255 - else if (!strcmp(arg, "--no-follow")) {
5256 - options->flags.follow_renames = 0;
5257 - options->flags.default_follow_renames = 0;
5258 - } else if (skip_to_optional_arg_default(arg, "--color", &arg, "always")) {
5271 + if (skip_to_optional_arg_default(arg, "--color", &arg, "always")) {
5272 int value = git_config_colorbool(NULL, arg);
5273 if (value < 0)
5274 return error("option `color' expects \"always\", \"auto\", or \"never\"");