]> git.ipfire.org Git - thirdparty/git.git/blobdiff - diff.c
diff-parseopt: convert --full-index
[thirdparty/git.git] / diff.c
diff --git a/diff.c b/diff.c
index b9c267a19977061ebeaf0678fd219247e02bbb9b..3a13ba37fd68203967036864d100033f35e71595 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -4839,6 +4839,31 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
        return 1;
 }
 
+static int diff_opt_anchored(const struct option *opt,
+                            const char *arg, int unset)
+{
+       struct diff_options *options = opt->value;
+
+       BUG_ON_OPT_NEG(unset);
+       options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
+       ALLOC_GROW(options->anchors, options->anchors_nr + 1,
+                  options->anchors_alloc);
+       options->anchors[options->anchors_nr++] = xstrdup(arg);
+       return 0;
+}
+
+static int diff_opt_binary(const struct option *opt,
+                          const char *arg, int unset)
+{
+       struct diff_options *options = opt->value;
+
+       BUG_ON_OPT_NEG(unset);
+       BUG_ON_OPT_ARG(arg);
+       enable_patch_output(&options->output_format);
+       options->flags.binary = 1;
+       return 0;
+}
+
 static int diff_opt_break_rewrites(const struct option *opt,
                                   const char *arg, int unset)
 {
@@ -4891,6 +4916,24 @@ static int diff_opt_compact_summary(const struct option *opt,
        return 0;
 }
 
+static int diff_opt_diff_algorithm(const struct option *opt,
+                                  const char *arg, int unset)
+{
+       struct diff_options *options = opt->value;
+       long value = parse_algorithm_value(arg);
+
+       BUG_ON_OPT_NEG(unset);
+       if (value < 0)
+               return error(_("option diff-algorithm accepts \"myers\", "
+                              "\"minimal\", \"patience\" and \"histogram\""));
+
+       /* clear out previous settings */
+       DIFF_XDL_CLR(options, NEED_MINIMAL);
+       options->xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK;
+       options->xdl_opts |= value;
+       return 0;
+}
+
 static int diff_opt_dirstat(const struct option *opt,
                            const char *arg, int unset)
 {
@@ -4960,6 +5003,26 @@ static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
        return 0;
 }
 
+static int diff_opt_patience(const struct option *opt,
+                            const char *arg, int unset)
+{
+       struct diff_options *options = opt->value;
+       int i;
+
+       BUG_ON_OPT_NEG(unset);
+       BUG_ON_OPT_ARG(arg);
+       options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
+       /*
+        * Both --patience and --anchored use PATIENCE_DIFF
+        * internally, so remove any anchors previously
+        * specified.
+        */
+       for (i = 0; i < options->anchors_nr; i++)
+               free(options->anchors[i]);
+       options->anchors_nr = 0;
+       return 0;
+}
+
 static int diff_opt_relative(const struct option *opt,
                             const char *arg, int unset)
 {
@@ -5065,6 +5128,11 @@ static void prep_parse_options(struct diff_options *options)
                OPT_CALLBACK_F(0, "compact-summary", options, NULL,
                               N_("generate compact summary in diffstat"),
                               PARSE_OPT_NOARG, diff_opt_compact_summary),
+               OPT_CALLBACK_F(0, "binary", options, NULL,
+                              N_("output a binary diff that can be applied"),
+                              PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_binary),
+               OPT_BOOL(0, "full-index", &options->flags.full_index,
+                        N_("show full pre- and post-image object names on the \"index\" lines")),
                OPT_CALLBACK_F(0, "output-indicator-new",
                               &options->output_indicators[OUTPUT_INDICATOR_NEW],
                               N_("<char>"),
@@ -5105,6 +5173,42 @@ static void prep_parse_options(struct diff_options *options)
                OPT_BOOL(0, "rename-empty", &options->flags.rename_empty,
                         N_("use empty blobs as rename source")),
 
+               OPT_GROUP(N_("Diff algorithm options")),
+               OPT_BIT(0, "minimal", &options->xdl_opts,
+                       N_("produce the smallest possible diff"),
+                       XDF_NEED_MINIMAL),
+               OPT_BIT_F('w', "ignore-all-space", &options->xdl_opts,
+                         N_("ignore whitespace when comparing lines"),
+                         XDF_IGNORE_WHITESPACE, PARSE_OPT_NONEG),
+               OPT_BIT_F('b', "ignore-space-change", &options->xdl_opts,
+                         N_("ignore changes in amount of whitespace"),
+                         XDF_IGNORE_WHITESPACE_CHANGE, PARSE_OPT_NONEG),
+               OPT_BIT_F(0, "ignore-space-at-eol", &options->xdl_opts,
+                         N_("ignore changes in whitespace at EOL"),
+                         XDF_IGNORE_WHITESPACE_AT_EOL, PARSE_OPT_NONEG),
+               OPT_BIT_F(0, "ignore-cr-at-eol", &options->xdl_opts,
+                         N_("ignore carrier-return at the end of line"),
+                         XDF_IGNORE_CR_AT_EOL, PARSE_OPT_NONEG),
+               OPT_BIT_F(0, "ignore-blank-lines", &options->xdl_opts,
+                         N_("ignore changes whose lines are all blank"),
+                         XDF_IGNORE_BLANK_LINES, PARSE_OPT_NONEG),
+               OPT_BIT(0, "indent-heuristic", &options->xdl_opts,
+                       N_("heuristic to shift diff hunk boundaries for easy reading"),
+                       XDF_INDENT_HEURISTIC),
+               OPT_CALLBACK_F(0, "patience", options, NULL,
+                              N_("generate diff using the \"patience diff\" algorithm"),
+                              PARSE_OPT_NONEG | PARSE_OPT_NOARG,
+                              diff_opt_patience),
+               OPT_BITOP(0, "histogram", &options->xdl_opts,
+                         N_("generate diff using the \"histogram diff\" algorithm"),
+                         XDF_HISTOGRAM_DIFF, XDF_DIFF_ALGORITHM_MASK),
+               OPT_CALLBACK_F(0, "diff-algorithm", options, N_("<algorithm>"),
+                              N_("choose a diff algorithm"),
+                              PARSE_OPT_NONEG, diff_opt_diff_algorithm),
+               OPT_CALLBACK_F(0, "anchored", options, N_("<text>"),
+                              N_("generate diff using the \"anchored diff\" algorithm"),
+                              PARSE_OPT_NONEG, diff_opt_anchored),
+
                OPT_GROUP(N_("Diff other options")),
                OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
                               N_("when run from subdir, exclude changes outside and show relative paths"),
@@ -5141,63 +5245,8 @@ int diff_opt_parse(struct diff_options *options,
        if (ac)
                return ac;
 
-       /* xdiff options */
-       if (!strcmp(arg, "--minimal"))
-               DIFF_XDL_SET(options, NEED_MINIMAL);
-       else if (!strcmp(arg, "--no-minimal"))
-               DIFF_XDL_CLR(options, NEED_MINIMAL);
-       else if (!strcmp(arg, "-w") || !strcmp(arg, "--ignore-all-space"))
-               DIFF_XDL_SET(options, IGNORE_WHITESPACE);
-       else if (!strcmp(arg, "-b") || !strcmp(arg, "--ignore-space-change"))
-               DIFF_XDL_SET(options, IGNORE_WHITESPACE_CHANGE);
-       else if (!strcmp(arg, "--ignore-space-at-eol"))
-               DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);
-       else if (!strcmp(arg, "--ignore-cr-at-eol"))
-               DIFF_XDL_SET(options, IGNORE_CR_AT_EOL);
-       else if (!strcmp(arg, "--ignore-blank-lines"))
-               DIFF_XDL_SET(options, IGNORE_BLANK_LINES);
-       else if (!strcmp(arg, "--indent-heuristic"))
-               DIFF_XDL_SET(options, INDENT_HEURISTIC);
-       else if (!strcmp(arg, "--no-indent-heuristic"))
-               DIFF_XDL_CLR(options, INDENT_HEURISTIC);
-       else if (!strcmp(arg, "--patience")) {
-               int i;
-               options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
-               /*
-                * Both --patience and --anchored use PATIENCE_DIFF
-                * internally, so remove any anchors previously
-                * specified.
-                */
-               for (i = 0; i < options->anchors_nr; i++)
-                       free(options->anchors[i]);
-               options->anchors_nr = 0;
-       } else if (!strcmp(arg, "--histogram"))
-               options->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF);
-       else if ((argcount = parse_long_opt("diff-algorithm", av, &optarg))) {
-               long value = parse_algorithm_value(optarg);
-               if (value < 0)
-                       return error("option diff-algorithm accepts \"myers\", "
-                                    "\"minimal\", \"patience\" and \"histogram\"");
-               /* clear out previous settings */
-               DIFF_XDL_CLR(options, NEED_MINIMAL);
-               options->xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK;
-               options->xdl_opts |= value;
-               return argcount;
-       } else if (skip_prefix(arg, "--anchored=", &arg)) {
-               options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
-               ALLOC_GROW(options->anchors, options->anchors_nr + 1,
-                          options->anchors_alloc);
-               options->anchors[options->anchors_nr++] = xstrdup(arg);
-       }
-
        /* flags options */
-       else if (!strcmp(arg, "--binary")) {
-               enable_patch_output(&options->output_format);
-               options->flags.binary = 1;
-       }
-       else if (!strcmp(arg, "--full-index"))
-               options->flags.full_index = 1;
-       else if (!strcmp(arg, "-a") || !strcmp(arg, "--text"))
+       if (!strcmp(arg, "-a") || !strcmp(arg, "--text"))
                options->flags.text = 1;
        else if (!strcmp(arg, "-R"))
                options->flags.reverse_diff = 1;