mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-12 14:43:08 +00:00
Add git_config_del to delete a variable
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
This commit is contained in:
parent
9f86ec52fa
commit
6d4b609718
@ -167,15 +167,15 @@ int git_config_foreach(git_config *cfg, int (*fn)(const char *, const char *, vo
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int git_config_del(git_config *cfg, const char *name)
|
||||||
|
{
|
||||||
|
return git_config_set_string(cfg, name, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/**************
|
/**************
|
||||||
* Setters
|
* 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)
|
int git_config_set_long(git_config *cfg, const char *name, long int value)
|
||||||
{
|
{
|
||||||
char str_value[32]; /* All numbers should fit in here */
|
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, '.');
|
last_dot = strrchr(name, '.');
|
||||||
if (last_dot == NULL) {
|
if (last_dot == NULL) {
|
||||||
return git__throw(GIT_EINVALIDTYPE, "Variables without section aren't allowed");
|
return git__throw(GIT_EINVALIDTYPE, "Variables without section aren't allowed");
|
||||||
@ -1011,8 +1016,15 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Then replace the variable */
|
/*
|
||||||
error = git_filebuf_printf(&file, "\t%s = %s\n", var->name, var->value);
|
* 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) {
|
if (error < GIT_SUCCESS) {
|
||||||
git__rethrow(error, "Failed to overwrite the variable");
|
git__rethrow(error, "Failed to overwrite the variable");
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user