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>
This commit is contained in:

committed by
Junio C Hamano

parent
17b3e51505
commit
a73b3680c4
13
config.c
13
config.c
@ -3245,3 +3245,16 @@ enum config_scope current_config_scope(void)
|
||||
else
|
||||
return current_parsing_scope;
|
||||
}
|
||||
|
||||
int lookup_config(const char **mapping, int nr_mapping, const char *var)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nr_mapping; i++) {
|
||||
const char *name = mapping[i];
|
||||
|
||||
if (name && !strcasecmp(var, name))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user