All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Sandro Santilli <strk@kbt.io>, git@vger.kernel.org
Subject: Re: color.diff.whitespace unused on removed lines
Date: Tue, 04 Oct 2016 10:57:11 -0700	[thread overview]
Message-ID: <xmqqk2douhe0.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20161004161323.53qec37i2tujaxcy@sigill.intra.peff.net> (Jeff King's message of "Tue, 4 Oct 2016 12:13:24 -0400")

Jeff King <peff@peff.net> writes:

> On Tue, Oct 04, 2016 at 05:35:23PM +0200, Sandro Santilli wrote:
>
>> > We later did b8767f7 (diff.c: --ws-error-highlight=<kind> option,
>> > 2015-05-26) to let you see them on other lines, though. I think that
>> > would do what you want.
>> 
>> Thanks, it does do what I want.
>> Any chance to specify it in the config file that I want it
>> always to behave in a certain way ?
>
> No, I don't think there's currently a matching config option. You can
> use an alias, or propose a patch to add a config option.

The final shape of such a patch would include something like the
attached.  It would need to be split into a few patches and then get
additional tests and documentation written, so I won't be committing
it myself in this shape.


 diff.c | 84 +++++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 50 insertions(+), 34 deletions(-)

diff --git a/diff.c b/diff.c
index a178ed39bc..a2193c3aea 100644
--- a/diff.c
+++ b/diff.c
@@ -43,6 +43,7 @@ static int diff_stat_graph_width;
 static int diff_dirstat_permille_default = 30;
 static struct diff_options default_diff_options;
 static long diff_algorithm;
+static unsigned ws_error_highlight_default = WSEH_NEW;
 
 static char diff_colors[][COLOR_MAXLEN] = {
 	GIT_COLOR_RESET,
@@ -172,6 +173,42 @@ long parse_algorithm_value(const char *value)
 	return -1;
 }
 
+static int parse_one_token(const char **arg, const char *token)
+{
+	const char *rest;
+	if (skip_prefix(*arg, token, &rest) && (!*rest || *rest == ',')) {
+		*arg = rest;
+		return 1;
+	}
+	return 0;
+}
+
+static int parse_ws_error_highlight(const char *arg)
+{
+	const char *orig_arg = arg;
+	unsigned val = 0;
+	while (*arg) {
+		if (parse_one_token(&arg, "none"))
+			val = 0;
+		else if (parse_one_token(&arg, "default"))
+			val = WSEH_NEW;
+		else if (parse_one_token(&arg, "all"))
+			val = WSEH_NEW | WSEH_OLD | WSEH_CONTEXT;
+		else if (parse_one_token(&arg, "new"))
+			val |= WSEH_NEW;
+		else if (parse_one_token(&arg, "old"))
+			val |= WSEH_OLD;
+		else if (parse_one_token(&arg, "context"))
+			val |= WSEH_CONTEXT;
+		else {
+			return (orig_arg - arg);
+		}
+		if (*arg)
+			arg++;
+	}
+	return val;
+}
+
 /*
  * These are to give UI layer defaults.
  * The core-level commands such as git-diff-files should
@@ -254,6 +291,11 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (!strcmp(var, "diff.wserrorhighlight")) {
+		ws_error_highlight_default = parse_ws_error_highlight(value);
+		return 0;
+	}
+
 	if (git_diff_heuristic_config(var, value, cb) < 0)
 		return -1;
 	if (git_color_config(var, value, cb) < 0)
@@ -3307,7 +3349,7 @@ void diff_setup(struct diff_options *options)
 	options->rename_limit = -1;
 	options->dirstat_permille = diff_dirstat_permille_default;
 	options->context = diff_context_default;
-	options->ws_error_highlight = WSEH_NEW;
+	options->ws_error_highlight = ws_error_highlight_default;
 	DIFF_OPT_SET(options, RENAME_EMPTY);
 
 	/* pathchange left =NULL by default */
@@ -3698,40 +3740,14 @@ static void enable_patch_output(int *fmt) {
 	*fmt |= DIFF_FORMAT_PATCH;
 }
 
-static int parse_one_token(const char **arg, const char *token)
+static int parse_ws_error_highlight_opt(struct diff_options *opt, const char *arg)
 {
-	const char *rest;
-	if (skip_prefix(*arg, token, &rest) && (!*rest || *rest == ',')) {
-		*arg = rest;
-		return 1;
-	}
-	return 0;
-}
+	int val = parse_ws_error_highlight(arg);
 
-static int parse_ws_error_highlight(struct diff_options *opt, const char *arg)
-{
-	const char *orig_arg = arg;
-	unsigned val = 0;
-	while (*arg) {
-		if (parse_one_token(&arg, "none"))
-			val = 0;
-		else if (parse_one_token(&arg, "default"))
-			val = WSEH_NEW;
-		else if (parse_one_token(&arg, "all"))
-			val = WSEH_NEW | WSEH_OLD | WSEH_CONTEXT;
-		else if (parse_one_token(&arg, "new"))
-			val |= WSEH_NEW;
-		else if (parse_one_token(&arg, "old"))
-			val |= WSEH_OLD;
-		else if (parse_one_token(&arg, "context"))
-			val |= WSEH_CONTEXT;
-		else {
-			error("unknown value after ws-error-highlight=%.*s",
-			      (int)(arg - orig_arg), orig_arg);
-			return 0;
-		}
-		if (*arg)
-			arg++;
+	if (val < 0) {
+		error("unknown value after ws-error-highlight=%.*s",
+		      -val, arg);
+		return 0;
 	}
 	opt->ws_error_highlight = val;
 	return 1;
@@ -3950,7 +3966,7 @@ int diff_opt_parse(struct diff_options *options,
 	else if (skip_prefix(arg, "--submodule=", &arg))
 		return parse_submodule_opt(options, arg);
 	else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
-		return parse_ws_error_highlight(options, arg);
+		return parse_ws_error_highlight_opt(options, arg);
 
 	/* misc options */
 	else if (!strcmp(arg, "-z"))

  reply	other threads:[~2016-10-04 17:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-04  8:14 color.diff.whitespace unused on removed lines Sandro Santilli
2016-10-04 15:29 ` Jeff King
2016-10-04 15:35   ` Sandro Santilli
2016-10-04 16:13     ` Jeff King
2016-10-04 17:57       ` Junio C Hamano [this message]
2016-10-04 22:54         ` [PATCH 0/4] diff.wsErrorHighlight configuration variable Junio C Hamano
2016-10-04 22:54           ` [PATCH 1/4] t4015: split out the "setup" part of ws-error-highlight test Junio C Hamano
2016-10-04 22:54           ` [PATCH 2/4] diff.c: refactor parse_ws_error_highlight() Junio C Hamano
2016-10-04 22:54           ` [PATCH 3/4] diff.c: move ws-error-highlight parsing helpers up Junio C Hamano
2016-10-04 22:54           ` [PATCH 4/4] diff: introduce diff.wsErrorHighlight option Junio C Hamano
2016-10-18 11:01           ` [PATCH 0/4] diff.wsErrorHighlight configuration variable Jeff King

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=xmqqk2douhe0.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=strk@kbt.io \
    /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.