Skip to content

Commit df84a43

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 10f35b1 commit df84a43

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

diff.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4839,6 +4839,19 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
48394839
return 1;
48404840
}
48414841

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+
48424855
static int diff_opt_break_rewrites(const struct option *opt,
48434856
const char *arg, int unset)
48444857
{
@@ -5175,6 +5188,9 @@ static void prep_parse_options(struct diff_options *options)
51755188
OPT_CALLBACK_F(0, "diff-algorithm", options, N_("<algorithm>"),
51765189
N_("choose a diff algorithm"),
51775190
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),
51785194

51795195
OPT_GROUP(N_("Diff other options")),
51805196
OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5212,16 +5228,8 @@ int diff_opt_parse(struct diff_options *options,
52125228
if (ac)
52135229
return ac;
52145230

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-
52235231
/* flags options */
5224-
else if (!strcmp(arg, "--binary")) {
5232+
if (!strcmp(arg, "--binary")) {
52255233
enable_patch_output(&options->output_format);
52265234
options->flags.binary = 1;
52275235
}

0 commit comments

Comments
 (0)