diff-parseopt: convert --patience
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
31fd640e95946782bcebbab26cb4ceba42b227ef
1 file changed
+25
-12
diff.c
+25
-12
@@ -4960,6 +4960,26 @@ static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
4960
return 0;
4961
}
4962
4963
+static int diff_opt_patience(const struct option *opt,
4964
+ const char *arg, int unset)
4965
+{
4966
+ struct diff_options *options = opt->value;
4967
+ int i;
4968
+
4969
+ BUG_ON_OPT_NEG(unset);
4970
+ BUG_ON_OPT_ARG(arg);
4971
+ options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
4972
+ /*
4973
+ * Both --patience and --anchored use PATIENCE_DIFF
4974
+ * internally, so remove any anchors previously
4975
+ * specified.
4976
+ */
4977
+ for (i = 0; i < options->anchors_nr; i++)
4978
+ free(options->anchors[i]);
4979
+ options->anchors_nr = 0;
4980
+ return 0;
4981
+}
4982
+
4983
static int diff_opt_relative(const struct option *opt,
4984
const char *arg, int unset)
4985
{
@@ -5127,6 +5147,10 @@ static void prep_parse_options(struct diff_options *options)
5147
OPT_BIT(0, "indent-heuristic", &options->xdl_opts,
5148
N_("heuristic to shift diff hunk boundaries for easy reading"),
5149
XDF_INDENT_HEURISTIC),
5150
+ OPT_CALLBACK_F(0, "patience", options, NULL,
5151
+ N_("generate diff using the \"patience diff\" algorithm"),
5152
+ PARSE_OPT_NONEG | PARSE_OPT_NOARG,
5153
+ diff_opt_patience),
5154
5155
OPT_GROUP(N_("Diff other options")),
5156
OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5165,18 +5189,7 @@ int diff_opt_parse(struct diff_options *options,
5189
return ac;
5190
5191
/* xdiff options */
5168
- if (!strcmp(arg, "--patience")) {
5169
- int i;
5170
- options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
5171
- /*
5172
- * Both --patience and --anchored use PATIENCE_DIFF
5173
- * internally, so remove any anchors previously
5174
- * specified.
5175
- */
5176
- for (i = 0; i < options->anchors_nr; i++)
5177
- free(options->anchors[i]);
5178
- options->anchors_nr = 0;
5179
- } else if (!strcmp(arg, "--histogram"))
5192
+ if (!strcmp(arg, "--histogram"))
5193
options->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF);
5194
else if ((argcount = parse_long_opt("diff-algorithm", av, &optarg))) {
5195
long value = parse_algorithm_value(optarg);