From 8852117a603c5ed5131233a80453db37c0958871 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 7 Oct 2014 15:16:57 -0400 Subject: pass config slots as pointers instead of offsets Many config-parsing helpers, like parse_branch_color_slot, take the name of a config variable and an offset to the "slot" name (e.g., "color.branch.plain" is passed along with "13" to effectively pass "plain"). This is leftover from the time that these functions would die() on error, and would want the full variable name for error reporting. These days they do not use the full variable name at all. Passing a single pointer to the slot name is more natural, and lets us more easily adjust the callers to use skip_prefix to avoid manually writing offset numbers. This is effectively a continuation of 9e1a5eb, which did the same for parse_diff_color_slot. This patch covers all of the remaining similar constructs. Signed-off-by: Jonathan Nieder Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- log-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 95e9b1da25..479b1d2a5b 100644 --- a/log-tree.c +++ b/log-tree.c @@ -66,9 +66,9 @@ static int parse_decorate_color_slot(const char *slot) return -1; } -int parse_decorate_color_config(const char *var, const int ofs, const char *value) +int parse_decorate_color_config(const char *var, const char *slot_name, const char *value) { - int slot = parse_decorate_color_slot(var + ofs); + int slot = parse_decorate_color_slot(slot_name); if (slot < 0) return 0; if (!value) -- cgit v1.2.3 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 --- log-tree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 479b1d2a5b..a21ef30d0c 100644 --- a/log-tree.c +++ b/log-tree.c @@ -73,8 +73,7 @@ int parse_decorate_color_config(const char *var, const char *slot_name, const ch return 0; if (!value) return config_error_nonbool(var); - color_parse(value, var, decoration_colors[slot]); - return 0; + return color_parse(value, decoration_colors[slot]); } /* -- cgit v1.2.3