From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: peff@peff.net, strk@kbt.io
Subject: [PATCH 2/4] diff.c: refactor parse_ws_error_highlight()
Date: Tue, 4 Oct 2016 15:54:47 -0700 [thread overview]
Message-ID: <20161004225449.6759-3-gitster@pobox.com> (raw)
In-Reply-To: <20161004225449.6759-1-gitster@pobox.com>
Rename the function to parse_ws_error_highlight_opt(), because it is
meant to parse a command line option, and then refactor the meat of
the function into a helper function that reports the parsed result
which is typically a small unsigned int (these are OR'ed bitmask
after all), or a negative offset that indicates where in the input
string a parse error happened.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
diff.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/diff.c b/diff.c
index 46260ed7a1..d346378600 100644
--- a/diff.c
+++ b/diff.c
@@ -3666,10 +3666,11 @@ static int parse_one_token(const char **arg, const char *token)
return 0;
}
-static int parse_ws_error_highlight(struct diff_options *opt, const char *arg)
+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;
@@ -3684,13 +3685,23 @@ static int parse_ws_error_highlight(struct diff_options *opt, const char *arg)
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;
+ return -1 - (int)(arg - orig_arg);
}
if (*arg)
arg++;
}
+ return val;
+}
+
+static int parse_ws_error_highlight_opt(struct diff_options *opt, const char *arg)
+{
+ int val = parse_ws_error_highlight(arg);
+
+ if (val < 0) {
+ error("unknown value after ws-error-highlight=%.*s",
+ -1 - val, arg);
+ return 0;
+ }
opt->ws_error_highlight = val;
return 1;
}
@@ -3894,7 +3905,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
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"))
--
2.10.1-510-g1ef781f2c1
next prev parent reply other threads:[~2016-10-04 22:55 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
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 ` Junio C Hamano [this message]
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161004225449.6759-3-gitster@pobox.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).