summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2014-10-07 15:33:09 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2014-10-14 11:01:21 -0700
commitf6c5a2968c103621adf6928a29e4895361eaa23b (patch)
tree60259098fe84c3a71ad16aea43d2dbfb38dd0ee3 /builtin
parentpass config slots as pointers instead of offsets (diff)
downloadtgif-f6c5a2968c103621adf6928a29e4895361eaa23b.tar.xz
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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/branch.c3
-rw-r--r--builtin/clean.c3
-rw-r--r--builtin/commit.c3
-rw-r--r--builtin/config.c9
-rw-r--r--builtin/for-each-ref.c6
5 files changed, 13 insertions, 11 deletions
diff --git a/builtin/branch.c b/builtin/branch.c
index b2e1895ca9..0a8ed9d22a 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -93,8 +93,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
return 0;
if (!value)
return config_error_nonbool(var);
- color_parse(value, var, branch_colors[slot]);
- return 0;
+ return color_parse(value, branch_colors[slot]);
}
return git_color_default_config(var, value, cb);
}
diff --git a/builtin/clean.c b/builtin/clean.c
index 1032563e5f..035ea391a2 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -116,8 +116,7 @@ static int git_clean_config(const char *var, const char *value, void *cb)
return 0;
if (!value)
return config_error_nonbool(var);
- color_parse(value, var, clean_colors[slot]);
- return 0;
+ return color_parse(value, clean_colors[slot]);
}
if (!strcmp(var, "clean.requireforce")) {
diff --git a/builtin/commit.c b/builtin/commit.c
index 5a8a29e075..8dab44d933 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1295,8 +1295,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
return 0;
if (!v)
return config_error_nonbool(k);
- color_parse(v, k, s->color_palette[slot]);
- return 0;
+ return color_parse(v, s->color_palette[slot]);
}
if (!strcmp(k, "status.relativepaths")) {
s->relative_paths = git_config_bool(k, v);
diff --git a/builtin/config.c b/builtin/config.c
index 7bba516383..842809b0b3 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -296,7 +296,8 @@ static int git_get_color_config(const char *var, const char *value, void *cb)
if (!strcmp(var, get_color_slot)) {
if (!value)
config_error_nonbool(var);
- color_parse(value, var, parsed_color);
+ if (color_parse(value, parsed_color) < 0)
+ return -1;
get_color_found = 1;
}
return 0;
@@ -309,8 +310,10 @@ static void get_color(const char *def_color)
git_config_with_options(git_get_color_config, NULL,
&given_config_source, respect_includes);
- if (!get_color_found && def_color)
- color_parse(def_color, "command line", parsed_color);
+ if (!get_color_found && def_color) {
+ if (color_parse(def_color, parsed_color) < 0)
+ die(_("unable to parse default color value"));
+ }
fputs(parsed_color, stdout);
}
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 47bd624696..d41920d382 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -673,7 +673,8 @@ static void populate_value(struct refinfo *ref)
} else if (starts_with(name, "color:")) {
char color[COLOR_MAXLEN] = "";
- color_parse(name + 6, "--format", color);
+ if (color_parse(name + 6, color) < 0)
+ die(_("unable to parse format"));
v->s = xstrdup(color);
continue;
} else if (!strcmp(name, "flag")) {
@@ -1007,7 +1008,8 @@ static void show_ref(struct refinfo *info, const char *format, int quote_style)
struct atom_value resetv;
char color[COLOR_MAXLEN] = "";
- color_parse("reset", "--format", color);
+ if (color_parse("reset", color) < 0)
+ die("BUG: couldn't parse 'reset' as a color");
resetv.s = color;
print_value(&resetv, quote_style);
}