From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: peff@peff.net, strk@kbt.io
Subject: [PATCH 3/4] diff.c: move ws-error-highlight parsing helpers up
Date: Tue, 4 Oct 2016 15:54:48 -0700 [thread overview]
Message-ID: <20161004225449.6759-4-gitster@pobox.com> (raw)
In-Reply-To: <20161004225449.6759-1-gitster@pobox.com>
These need to be usable from git_diff_ui_config() code to help
parsing a configuration variable, so move them up.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
diff.c | 74 +++++++++++++++++++++++++++++++++---------------------------------
1 file changed, 37 insertions(+), 37 deletions(-)
diff --git a/diff.c b/diff.c
index d346378600..bd625cf3f7 100644
--- a/diff.c
+++ b/diff.c
@@ -163,6 +163,43 @@ 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 -1 - (int)(arg - orig_arg);
+ }
+ if (*arg)
+ arg++;
+ }
+ return val;
+}
+
/*
* These are to give UI layer defaults.
* The core-level commands such as git-diff-files should
@@ -3656,43 +3693,6 @@ static void enable_patch_output(int *fmt) {
*fmt |= DIFF_FORMAT_PATCH;
}
-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 -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);
--
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 ` [PATCH 2/4] diff.c: refactor parse_ws_error_highlight() Junio C Hamano
2016-10-04 22:54 ` Junio C Hamano [this message]
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=20161004225449.6759-4-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.
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 NNTP newsgroup(s).