From f6c5a2968c103621adf6928a29e4895361eaa23b Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 7 Oct 2014 15:33:09 -0400 Subject: color_parse: do not mention variable name in error message Originally the color-parsing function was used only for config variables. It made sense to pass the variable name so that the die() message could be something like: $ git -c color.branch.plain=bogus branch fatal: bad color value 'bogus' for variable 'color.branch.plain' These days we call it in other contexts, and the resulting error messages are a little confusing: $ git log --pretty='%C(bogus)' fatal: bad color value 'bogus' for variable '--pretty format' $ git config --get-color foo.bar bogus fatal: bad color value 'bogus' for variable 'command line' This patch teaches color_parse to complain only about the value, and then return an error code. Config callers can then propagate that up to the config parser, which mentions the variable name. Other callers can provide a custom message. After this patch these three cases now look like: $ git -c color.branch.plain=bogus branch error: invalid color value: bogus fatal: unable to parse 'color.branch.plain' from command-line config $ git log --pretty='%C(bogus)' error: invalid color value: bogus fatal: unable to parse --pretty format $ git config --get-color foo.bar bogus error: invalid color value: bogus fatal: unable to parse default color value Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- color.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'color.c') diff --git a/color.c b/color.c index f672885b71..7941e932d2 100644 --- a/color.c +++ b/color.c @@ -60,13 +60,12 @@ static int parse_attr(const char *name, int len) return -1; } -void color_parse(const char *value, const char *var, char *dst) +int color_parse(const char *value, char *dst) { - color_parse_mem(value, strlen(value), var, dst); + return color_parse_mem(value, strlen(value), dst); } -void color_parse_mem(const char *value, int value_len, const char *var, - char *dst) +int color_parse_mem(const char *value, int value_len, char *dst) { const char *ptr = value; int len = value_len; @@ -76,7 +75,7 @@ void color_parse_mem(const char *value, int value_len, const char *var, if (!strncasecmp(value, "reset", len)) { strcpy(dst, GIT_COLOR_RESET); - return; + return 0; } /* [fg [bg]] [attr]... */ @@ -153,9 +152,9 @@ void color_parse_mem(const char *value, int value_len, const char *var, *dst++ = 'm'; } *dst = 0; - return; + return 0; bad: - die("bad color value '%.*s' for variable '%s'", value_len, value, var); + return error(_("invalid color value: %.*s"), value_len, value); } int git_config_colorbool(const char *var, const char *value) -- cgit v1.2.3