diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-10-04 15:09:18 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-10-04 15:49:05 -0700 |
commit | 0b4b42e7fe1b507fb387c18d9a2748768359bf5d (patch) | |
tree | 3d29464eb77f14283fb227957e4af3dba589a809 /diff.c | |
parent | 077965f84a580b7e1de7d60ed13656bec19cc2fb (diff) | |
download | git-0b4b42e7fe1b507fb387c18d9a2748768359bf5d.tar.gz |
diff.c: move ws-error-highlight parsing helpers up
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>
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 74 |
1 files changed, 37 insertions, 37 deletions
@@ -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); |