Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-05-26 16:55:21 +0300
committerJunio C Hamano <gitster@pobox.com>2018-05-29 08:51:28 +0300
commita73b3680c4910866e3e215c3927a0c71f0b9229d (patch)
tree4c48aca0f71bba28888b19f3dec47088334ea7d1 /builtin/clean.c
parent17b3e5150506281fd2d675c150cf1e71f914ad54 (diff)
Add and use generic name->id mapping code for color slot parsing
Instead of hard coding the name-to-id mapping in C code, keep it in an array and use a common function to do the parsing. This reduces code and also allows us to list all possible color slots later. This starts using C99 designated initializers more for convenience (the first designated initializers have been introduced in builtin/clean.c for some time without complaints) Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/clean.c')
-rw-r--r--builtin/clean.c28
1 files changed, 10 insertions, 18 deletions
diff --git a/builtin/clean.c b/builtin/clean.c
index fad533a0a7..0ccd95e693 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -42,6 +42,15 @@ enum color_clean {
CLEAN_COLOR_ERROR = 5
};
+static const char *color_interactive_slots[] = {
+ [CLEAN_COLOR_ERROR] = "error",
+ [CLEAN_COLOR_HEADER] = "header",
+ [CLEAN_COLOR_HELP] = "help",
+ [CLEAN_COLOR_PLAIN] = "plain",
+ [CLEAN_COLOR_PROMPT] = "prompt",
+ [CLEAN_COLOR_RESET] = "reset",
+};
+
static int clean_use_color = -1;
static char clean_colors[][COLOR_MAXLEN] = {
[CLEAN_COLOR_ERROR] = GIT_COLOR_BOLD_RED,
@@ -82,23 +91,6 @@ struct menu_stuff {
void *stuff;
};
-static int parse_clean_color_slot(const char *var)
-{
- if (!strcasecmp(var, "reset"))
- return CLEAN_COLOR_RESET;
- if (!strcasecmp(var, "plain"))
- return CLEAN_COLOR_PLAIN;
- if (!strcasecmp(var, "prompt"))
- return CLEAN_COLOR_PROMPT;
- if (!strcasecmp(var, "header"))
- return CLEAN_COLOR_HEADER;
- if (!strcasecmp(var, "help"))
- return CLEAN_COLOR_HELP;
- if (!strcasecmp(var, "error"))
- return CLEAN_COLOR_ERROR;
- return -1;
-}
-
static int git_clean_config(const char *var, const char *value, void *cb)
{
const char *slot_name;
@@ -113,7 +105,7 @@ static int git_clean_config(const char *var, const char *value, void *cb)
return 0;
}
if (skip_prefix(var, "color.interactive.", &slot_name)) {
- int slot = parse_clean_color_slot(slot_name);
+ int slot = LOOKUP_CONFIG(color_interactive_slots, slot_name);
if (slot < 0)
return 0;
if (!value)