Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2019-03-05 15:30:18 +0300
committerJunio C Hamano <gitster@pobox.com>2019-03-07 02:02:22 +0300
commite9fb39b668d5f2a083e70bb15e2cdf191cb10205 (patch)
tree5301937f815e6db9aae2be7a09cf0cbdf46d2fc5 /diff.c
parent8b81c26e5cfd139230d7f00660b9ed3586595545 (diff)
diff-parseopt: convert --word-diff
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.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/diff.c b/diff.c
index bb36d507ec..14c057f3df 100644
--- a/diff.c
+++ b/diff.c
@@ -5066,6 +5066,32 @@ static int diff_opt_unified(const struct option *opt,
return 0;
}
+static int diff_opt_word_diff(const struct option *opt,
+ const char *arg, int unset)
+{
+ struct diff_options *options = opt->value;
+
+ BUG_ON_OPT_NEG(unset);
+ if (arg) {
+ if (!strcmp(arg, "plain"))
+ options->word_diff = DIFF_WORDS_PLAIN;
+ else if (!strcmp(arg, "color")) {
+ options->use_color = 1;
+ options->word_diff = DIFF_WORDS_COLOR;
+ }
+ else if (!strcmp(arg, "porcelain"))
+ options->word_diff = DIFF_WORDS_PORCELAIN;
+ else if (!strcmp(arg, "none"))
+ options->word_diff = DIFF_WORDS_NONE;
+ else
+ return error(_("bad --word-diff argument: %s"), arg);
+ } else {
+ if (options->word_diff == DIFF_WORDS_NONE)
+ options->word_diff = DIFF_WORDS_PLAIN;
+ }
+ return 0;
+}
+
static void prep_parse_options(struct diff_options *options)
{
struct option parseopts[] = {
@@ -5228,6 +5254,9 @@ static void prep_parse_options(struct diff_options *options)
OPT_CALLBACK_F(0, "anchored", options, N_("<text>"),
N_("generate diff using the \"anchored diff\" algorithm"),
PARSE_OPT_NONEG, diff_opt_anchored),
+ OPT_CALLBACK_F(0, "word-diff", options, N_("<mode>"),
+ N_("show word diff, using <mode> to delimit changed words"),
+ PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_word_diff),
OPT_GROUP(N_("Diff other options")),
OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5291,24 +5320,6 @@ int diff_opt_parse(struct diff_options *options,
options->use_color = 1;
options->word_diff = DIFF_WORDS_COLOR;
}
- else if (!strcmp(arg, "--word-diff")) {
- if (options->word_diff == DIFF_WORDS_NONE)
- options->word_diff = DIFF_WORDS_PLAIN;
- }
- else if (skip_prefix(arg, "--word-diff=", &arg)) {
- if (!strcmp(arg, "plain"))
- options->word_diff = DIFF_WORDS_PLAIN;
- else if (!strcmp(arg, "color")) {
- options->use_color = 1;
- options->word_diff = DIFF_WORDS_COLOR;
- }
- else if (!strcmp(arg, "porcelain"))
- options->word_diff = DIFF_WORDS_PORCELAIN;
- else if (!strcmp(arg, "none"))
- options->word_diff = DIFF_WORDS_NONE;
- else
- die("bad --word-diff argument: %s", arg);
- }
else if ((argcount = parse_long_opt("word-diff-regex", av, &optarg))) {
if (options->word_diff == DIFF_WORDS_NONE)
options->word_diff = DIFF_WORDS_PLAIN;