All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 71/76] diff.c: convert --color-moved
Date: Thu, 17 Jan 2019 20:06:10 +0700	[thread overview]
Message-ID: <20190117130615.18732-72-pclouds@gmail.com> (raw)
In-Reply-To: <20190117130615.18732-1-pclouds@gmail.com>

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)

diff --git a/diff.c b/diff.c
index cc10b27df0..5403351466 100644
--- a/diff.c
+++ b/diff.c
@@ -4905,6 +4905,27 @@ static int diff_opt_char(const struct option *opt,
 	return 0;
 }
 
+static int diff_opt_color_moved(const struct option *opt,
+				const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	if (unset) {
+		options->color_moved = COLOR_MOVED_NO;
+	} else if (!arg) {
+		if (diff_color_moved_default)
+			options->color_moved = diff_color_moved_default;
+		if (options->color_moved == COLOR_MOVED_NO)
+			options->color_moved = COLOR_MOVED_DEFAULT;
+	} else {
+		int cm = parse_color_moved(arg);
+		if (cm < 0)
+			return error("bad --color-moved argument: %s", arg);
+		options->color_moved = cm;
+	}
+	return 0;
+}
+
 static int diff_opt_color_words(const struct option *opt,
 				const char *arg, int unset)
 {
@@ -5403,6 +5424,9 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_CALLBACK_F(0, "color-words", options, N_("<regex>"),
 			       N_("equivalent to --word-diff=color --word-diff-regex=<regex>"),
 			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_color_words),
+		OPT_CALLBACK_F(0, "color-moved", options, N_("<mode>"),
+			       N_("move lines of code are colored differently"),
+			       PARSE_OPT_OPTARG, diff_opt_color_moved),
 
 		OPT_GROUP(N_("Diff other options")),
 		OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5486,19 +5510,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* flags options */
-	if (!strcmp(arg, "--color-moved")) {
-		if (diff_color_moved_default)
-			options->color_moved = diff_color_moved_default;
-		if (options->color_moved == COLOR_MOVED_NO)
-			options->color_moved = COLOR_MOVED_DEFAULT;
-	} else if (!strcmp(arg, "--no-color-moved"))
-		options->color_moved = COLOR_MOVED_NO;
-	else if (skip_prefix(arg, "--color-moved=", &arg)) {
-		int cm = parse_color_moved(arg);
-		if (cm < 0)
-			return error("bad --color-moved argument: %s", arg);
-		options->color_moved = cm;
-	} else if (skip_prefix(arg, "--color-moved-ws=", &arg)) {
+	if (skip_prefix(arg, "--color-moved-ws=", &arg)) {
 		unsigned cm = parse_color_moved_ws(arg);
 		if (cm & COLOR_MOVED_WS_ERROR)
 			return -1;
-- 
2.20.0.482.g66447595a7


  parent reply	other threads:[~2019-01-17 13:12 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-17 13:04 [PATCH 00/76] Convert diff opt parser to parse_options() Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 01/76] parse-options.h: remove extern on function prototypes Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 02/76] parse-options: add one-shot mode Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 03/76] parse-options: allow keep-unknown + stop-at-non-opt combination Nguyễn Thái Ngọc Duy
2019-01-17 18:33   ` Stefan Beller
2019-01-17 13:05 ` [PATCH 04/76] parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 05/76] parse-options: add OPT_BITOP() Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 06/76] parse-options: stop abusing 'callback' for lowlevel callbacks Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 07/76] parse-options: avoid magic return codes Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 08/76] parse-options: allow ll_callback with OPTION_CALLBACK Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 09/76] diff.h: keep forward struct declarations sorted Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 10/76] diff.h: avoid bit fields in struct diff_flags Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 11/76] diff.c: prepare to use parse_options() for parsing Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 12/76] diff.c: convert -u|-p|--patch Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 13/76] diff.c: convert -U|--unified Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 14/76] diff.c: convert -W|--[no-]function-context Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 15/76] diff.c: convert --raw Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 16/76] diff.c: convert --patch-with-raw Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 17/76] diff.c: convert --numstat and --shortstat Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 18/76] diff.c: convert --dirstat and friends Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 19/76] diff.c: convert --check Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 20/76] diff.c: convert --summary Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 21/76] diff.c: convert --patch-with-stat Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 22/76] diff.c: convert --name-only Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 23/76] diff.c: convert --name-status Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 24/76] diff.c: convert -s|--no-patch Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 25/76] diff.c: convert --stat* Nguyễn Thái Ngọc Duy
2019-01-19  1:21   ` SZEDER Gábor
2019-01-17 13:05 ` [PATCH 26/76] diff.c: convert --[no-]compact-summary Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 27/76] diff.c: convert --output-* Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 28/76] diff.c: convert -B|--break-rewrites Nguyễn Thái Ngọc Duy
2019-01-21 12:07   ` Johannes Schindelin
2019-01-17 13:05 ` [PATCH 29/76] diff.c: convert -M|--find-renames Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 30/76] diff.c: convert -D|--irreversible-delete Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 31/76] diff.c: convert -C|--find-copies Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 32/76] diff.c: convert --find-copies-harder Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 33/76] diff.c: convert --no-renames|--[no--rename-empty Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 34/76] diff.c: convert --relative Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 35/76] diff.c: convert --[no-]minimal Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 36/76] diff.c: convert --ignore-some-changes Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 37/76] diff.c: convert --[no-]indent-heuristic Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 38/76] diff.c: convert --patience Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 39/76] diff.c: convert --histogram Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 40/76] diff.c: convert --diff-algorithm Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 41/76] diff.c: convert --anchored Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 42/76] diff.c: convert --binary Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 43/76] diff.c: convert --full-index Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 44/76] diff.c: convert -a|--text Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 45/76] diff.c: convert -R Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 46/76] diff.c: convert --[no-]follow Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 47/76] diff.c: convert --[no-]color Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 48/76] diff.c: convert --word-diff Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 49/76] diff.c: convert --word-diff-regex Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 50/76] diff.c: convert --color-words Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 51/76] diff.c: convert --exit-code Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 52/76] diff.c: convert --quiet Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 53/76] diff.c: convert --ext-diff Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 54/76] diff.c: convert --textconv Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 55/76] diff.c: convert --ignore-submodules Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 56/76] diff.c: convert --submodule Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 57/76] diff.c: convert --ws-error-highlight Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 58/76] diff.c: convert --ita-[in]visible-in-index Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 59/76] diff.c: convert -z Nguyễn Thái Ngọc Duy
2019-01-17 13:05 ` [PATCH 60/76] diff.c: convert -l Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 61/76] diff.c: convert -S|-G Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 62/76] diff.c: convert --pickaxe-all|--pickaxe-regex Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 63/76] diff.c: convert -O Nguyễn Thái Ngọc Duy
2019-01-21 12:14   ` Johannes Schindelin
2019-01-17 13:06 ` [PATCH 64/76] diff.c: convert --find-object Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 65/76] diff.c: convert --diff-filter Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 66/76] diff.c: convert --[no-]abbrev Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 67/76] diff.c: convert --[src|dst]-prefix Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 68/76] diff.c: convert --line-prefix Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 69/76] diff.c: convert --no-prefix Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 70/76] diff.c: convert --inter-hunk-context Nguyễn Thái Ngọc Duy
2019-01-19  1:18   ` SZEDER Gábor
2019-01-17 13:06 ` Nguyễn Thái Ngọc Duy [this message]
2019-01-17 13:06 ` [PATCH 72/76] diff.c: convert --color-moved-ws Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 73/76] diff.c: allow --no-color-moved-ws Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 74/76] range-diff: use parse_options() instead of diff_opt_parse() Nguyễn Thái Ngọc Duy
2019-01-17 19:46   ` Stefan Beller
2019-01-18  9:30     ` Duy Nguyen
2019-01-17 13:06 ` [PATCH 75/76] diff --no-index: " Nguyễn Thái Ngọc Duy
2019-01-17 13:06 ` [PATCH 76/76] am: avoid diff_opt_parse() Nguyễn Thái Ngọc Duy
2019-01-17 20:10   ` Johannes Schindelin
2019-01-18  0:19     ` Duy Nguyen
2019-01-17 14:32 ` [PATCH 00/76] Convert diff opt parser to parse_options() Ævar Arnfjörð Bjarmason
2019-01-17 19:50   ` Stefan Beller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190117130615.18732-72-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.