mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-08 10:53:16 +00:00
config: provide a function to reverse-lookup mapped cvars
This commit is contained in:
parent
7d6dacdc17
commit
15c3810313
20
src/config.c
20
src/config.c
@ -1194,6 +1194,26 @@ fail_parse:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int git_config_lookup_map_enum(git_cvar_t *type_out, const char **str_out,
|
||||||
|
const git_cvar_map *maps, size_t map_n, int enum_val)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < map_n; i++) {
|
||||||
|
const git_cvar_map *m = &maps[i];
|
||||||
|
|
||||||
|
if (m->map_value != enum_val)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
*type_out = m->cvar_type;
|
||||||
|
*str_out = m->str_match;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
giterr_set(GITERR_CONFIG, "invalid enum value");
|
||||||
|
return GIT_ENOTFOUND;
|
||||||
|
}
|
||||||
|
|
||||||
int git_config_parse_bool(int *out, const char *value)
|
int git_config_parse_bool(int *out, const char *value)
|
||||||
{
|
{
|
||||||
if (git__parse_bool(out, value) == 0)
|
if (git__parse_bool(out, value) == 0)
|
||||||
|
@ -82,4 +82,10 @@ extern int git_config__get_int_force(
|
|||||||
extern int git_config__cvar(
|
extern int git_config__cvar(
|
||||||
int *out, git_config *config, git_cvar_cached cvar);
|
int *out, git_config *config, git_cvar_cached cvar);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The opposite of git_config_lookup_map_value, we take an enum value
|
||||||
|
* and map it to the string or bool value on the config.
|
||||||
|
*/
|
||||||
|
int git_config_lookup_map_enum(git_cvar_t *type_out, const char **str_out,
|
||||||
|
const git_cvar_map *maps, size_t map_n, int enum_val);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user