summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2019-03-05 12:30:08 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-03-06 23:02:21 (GMT)
commit31fd640e95946782bcebbab26cb4ceba42b227ef (patch)
treee78b117edb8c54f42b7c8fae0454a3bae9f52b0d /diff.c
parent06f77518db2b6a88ffa27c7d4516840b78ee0d3a (diff)
downloadgit-31fd640e95946782bcebbab26cb4ceba42b227ef.zip
git-31fd640e95946782bcebbab26cb4ceba42b227ef.tar.gz
git-31fd640e95946782bcebbab26cb4ceba42b227ef.tar.bz2
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>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/diff.c b/diff.c
index c4cd84f..7899c7c 100644
--- a/diff.c
+++ b/diff.c
@@ -4960,6 +4960,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)
{
@@ -5127,6 +5147,10 @@ static void prep_parse_options(struct diff_options *options)
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_GROUP(N_("Diff other options")),
OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5165,18 +5189,7 @@ int diff_opt_parse(struct diff_options *options,
return ac;
/* xdiff options */
- 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"))
+ 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);