diff options
| author | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-12-16 02:28:39 +0100 |
|---|---|---|
| committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-12-16 02:28:39 +0100 |
| commit | 80a665aaca70ea3f5fda0955c39884bead13d2a2 (patch) | |
| tree | 73c1b97da7441e71ac129a58a8dad992e695a402 /src/config_file.c | |
| parent | 7b2b4adfb1cb71f085a88418d1d5b631bf26ebd8 (diff) | |
| download | libgit2-80a665aaca70ea3f5fda0955c39884bead13d2a2.tar.gz | |
config: really delete variables
Instead of just setting the value to NULL, which gives unwanted
results when asking for that variable after deleting it, delete the
variable from the list and re-write the file.
Diffstat (limited to 'src/config_file.c')
| -rw-r--r-- | src/config_file.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/config_file.c b/src/config_file.c index 7a5865210..207bd2bdd 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -404,6 +404,32 @@ static int config_get(git_config_file *cfg, const char *name, const char **out) return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to get config value for %s", name); } +static int config_delete(git_config_file *cfg, const char *name) +{ + cvar_t *iter, *prev; + diskfile_backend *b = (diskfile_backend *)cfg; + + CVAR_LIST_FOREACH (&b->var_list, iter) { + /* This is a bit hacky because we use a singly-linked list */ + if (cvar_match_name(iter, name)) { + if (CVAR_LIST_HEAD(&b->var_list) == iter) + CVAR_LIST_HEAD(&b->var_list) = CVAR_LIST_NEXT(iter); + else + CVAR_LIST_REMOVE_AFTER(prev); + + git__free(iter->value); + iter->value = NULL; + config_write(b, iter); + cvar_free(iter); + return GIT_SUCCESS; + } + /* Store it for the next round */ + prev = iter; + } + + return git__throw(GIT_ENOTFOUND, "Variable '%s' not found", name); +} + int git_config_file__ondisk(git_config_file **out, const char *path) { diskfile_backend *backend; @@ -423,6 +449,7 @@ int git_config_file__ondisk(git_config_file **out, const char *path) backend->parent.open = config_open; backend->parent.get = config_get; backend->parent.set = config_set; + backend->parent.delete = config_delete; backend->parent.foreach = file_foreach; backend->parent.free = backend_free; |
