Commit c4e3a3db by Carlos Martín Nieto

submodule: handle writing out all enum values for settings

We currently do not handle those enum values which require us to set
"true" or unset variables in all cases. Use a common function which does
understand this by looking at our mapping directly.
parent 15c38103
......@@ -737,15 +737,6 @@ cleanup:
return error;
}
const char *git_submodule_ignore_to_str(git_submodule_ignore_t ignore)
{
int i;
for (i = 0; i < (int)ARRAY_SIZE(_sm_ignore_map); ++i)
if (_sm_ignore_map[i].map_value == ignore)
return _sm_ignore_map[i].str_match;
return NULL;
}
const char *git_submodule_update_to_str(git_submodule_update_t update)
{
int i;
......@@ -755,15 +746,6 @@ const char *git_submodule_update_to_str(git_submodule_update_t update)
return NULL;
}
const char *git_submodule_recurse_to_str(git_submodule_recurse_t recurse)
{
int i;
for (i = 0; i < (int)ARRAY_SIZE(_sm_recurse_map); ++i)
if (_sm_recurse_map[i].map_value == recurse)
return _sm_recurse_map[i].str_match;
return NULL;
}
git_repository *git_submodule_owner(git_submodule *submodule)
{
assert(submodule);
......@@ -834,6 +816,22 @@ cleanup:
return error;
}
static int write_mapped_var(git_repository *repo, const char *name, git_cvar_map *maps, size_t nmaps, const char *var, int ival)
{
git_cvar_t type;
const char *val;
if (git_config_lookup_map_enum(&type, &val, maps, nmaps, ival) < 0) {
giterr_set(GITERR_SUBMODULE, "invalid value for %s", var);
return -1;
}
if (type == GIT_CVAR_TRUE)
val = "true";
return write_var(repo, name, var, val);
}
const char *git_submodule_branch(git_submodule *submodule)
{
assert(submodule);
......@@ -905,18 +903,9 @@ git_submodule_ignore_t git_submodule_ignore(git_submodule *submodule)
int git_submodule_set_ignore(git_repository *repo, const char *name, git_submodule_ignore_t ignore)
{
const char *val;
int error;
val = git_submodule_ignore_to_str(ignore);
if (!val) {
giterr_set(GITERR_SUBMODULE, "invalid ignore value");
return -1;
}
error = write_var(repo, name, "ignore", val);
assert(repo && name);
return error;
return write_mapped_var(repo, name, _sm_ignore_map, ARRAY_SIZE(_sm_ignore_map), "ignore", ignore);
}
git_submodule_update_t git_submodule_update_strategy(git_submodule *submodule)
......@@ -928,18 +917,9 @@ git_submodule_update_t git_submodule_update_strategy(git_submodule *submodule)
int git_submodule_set_update(git_repository *repo, const char *name, git_submodule_update_t update)
{
const char *val;
int error;
val = git_submodule_update_to_str(update);
if (!val) {
giterr_set(GITERR_SUBMODULE, "invalid update value");
return -1;
}
error = write_var(repo, name, "update", val);
assert(repo && name);
return error;
return write_mapped_var(repo, name, _sm_update_map, ARRAY_SIZE(_sm_update_map), "update", update);
}
git_submodule_recurse_t git_submodule_fetch_recurse_submodules(
......@@ -951,29 +931,9 @@ git_submodule_recurse_t git_submodule_fetch_recurse_submodules(
int git_submodule_set_fetch_recurse_submodules(git_repository *repo, const char *name, git_submodule_recurse_t recurse)
{
const char *val;
int error;
assert(repo && name);
val = git_submodule_recurse_to_str(recurse);
if (!val) {
switch (recurse) {
case GIT_SUBMODULE_RECURSE_YES:
val = "true";
break;
case GIT_SUBMODULE_RECURSE_NO:
val = NULL;
break;
default:
giterr_set(GITERR_SUBMODULE, "invalid recurse value");
return -1;
}
}
error = write_var(repo, name, "fetchRecurseSubmodules", val);
return error;
return write_mapped_var(repo, name, _sm_recurse_map, ARRAY_SIZE(_sm_recurse_map), "fetchRecurseSubmodules", recurse);
}
static int submodule_repo_create(
......
......@@ -143,8 +143,4 @@ extern int git_submodule_parse_ignore(
extern int git_submodule_parse_update(
git_submodule_update_t *out, const char *value);
extern const char *git_submodule_ignore_to_str(git_submodule_ignore_t);
extern const char *git_submodule_update_to_str(git_submodule_update_t);
extern const char *git_submodule_recurse_to_str(git_submodule_recurse_t);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment