Commit 6d4b6097 by Carlos Martín Nieto Committed by Vicent Marti

Add git_config_del to delete a variable

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
parent 9f86ec52
......@@ -167,15 +167,15 @@ int git_config_foreach(git_config *cfg, int (*fn)(const char *, const char *, vo
return ret;
}
int git_config_del(git_config *cfg, const char *name)
{
return git_config_set_string(cfg, name, NULL);
}
/**************
* Setters
**************/
/*
* Internal function to actually set the string value of a variable
*/
int git_config_set_long(git_config *cfg, const char *name, long int value)
{
char str_value[32]; /* All numbers should fit in here */
......
......@@ -356,9 +356,14 @@ static int config_set(git_config_file *cfg, const char *name, const char *value)
}
/*
* Otherwise, create it and stick it at the end of the queue.
* Otherwise, create it and stick it at the end of the queue. If
* value is NULL, we return an error, because you can't delete a
* variable that doesn't exist.
*/
if (value == NULL)
return git__throw(GIT_ENOTFOUND, "Can't delete non-exitent variable");
last_dot = strrchr(name, '.');
if (last_dot == NULL) {
return git__throw(GIT_EINVALIDTYPE, "Variables without section aren't allowed");
......@@ -1011,7 +1016,14 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
break;
}
/* Then replace the variable */
/*
* Then replace the variable. If the value is NULL, it
* means we want to delete it, so pretend everything went
* fine
*/
if (var->value == NULL)
error = GIT_SUCCESS;
else
error = git_filebuf_printf(&file, "\t%s = %s\n", var->name, var->value);
if (error < GIT_SUCCESS) {
git__rethrow(error, "Failed to overwrite the variable");
......
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