diff-parseopt: convert --anchored
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
df84a436270ff44d32c085976bea17175aa7077b
1 file changed
+17
-9
diff.c
+17
-9
@@ -4839,6 +4839,19 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
4839
return 1;
4840
}
4841
4842
+static int diff_opt_anchored(const struct option *opt,
4843
+ const char *arg, int unset)
4844
+{
4845
+ struct diff_options *options = opt->value;
4846
+
4847
+ BUG_ON_OPT_NEG(unset);
4848
+ options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
4849
+ ALLOC_GROW(options->anchors, options->anchors_nr + 1,
4850
+ options->anchors_alloc);
4851
+ options->anchors[options->anchors_nr++] = xstrdup(arg);
4852
+ return 0;
4853
+}
4854
+
4855
static int diff_opt_break_rewrites(const struct option *opt,
4856
const char *arg, int unset)
4857
{
@@ -5175,6 +5188,9 @@ static void prep_parse_options(struct diff_options *options)
5188
OPT_CALLBACK_F(0, "diff-algorithm", options, N_("<algorithm>"),
5189
N_("choose a diff algorithm"),
5190
PARSE_OPT_NONEG, diff_opt_diff_algorithm),
5191
+ OPT_CALLBACK_F(0, "anchored", options, N_("<text>"),
5192
+ N_("generate diff using the \"anchored diff\" algorithm"),
5193
+ PARSE_OPT_NONEG, diff_opt_anchored),
5194
5195
OPT_GROUP(N_("Diff other options")),
5196
OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5212,16 +5228,8 @@ int diff_opt_parse(struct diff_options *options,
5228
if (ac)
5229
return ac;
5230
5215
- /* xdiff options */
5216
- if (skip_prefix(arg, "--anchored=", &arg)) {
5217
- options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
5218
- ALLOC_GROW(options->anchors, options->anchors_nr + 1,
5219
- options->anchors_alloc);
5220
- options->anchors[options->anchors_nr++] = xstrdup(arg);
5221
- }
5222
-
5231
/* flags options */
5224
- else if (!strcmp(arg, "--binary")) {
5232
+ if (!strcmp(arg, "--binary")) {
5233
enable_patch_output(&options->output_format);
5234
options->flags.binary = 1;
5235
}