mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-03 10:47:28 +00:00
config: remove the refresh function and backend field
We have been refreshing on read and write for a while now, so git_config_refresh() is at best a no-op, and might just end up wasting cycles.
This commit is contained in:
parent
4bb6ffb6bb
commit
55cb499972
@ -242,20 +242,6 @@ GIT_EXTERN(int) git_config_open_global(git_config **out, git_config *config);
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_snapshot(git_config **out, git_config *config);
|
||||
|
||||
|
||||
/**
|
||||
* Reload changed config files
|
||||
*
|
||||
* A config file may be changed on disk out from under the in-memory
|
||||
* config object. This function causes us to look for files that have
|
||||
* been modified since we last loaded them and refresh the config with
|
||||
* the latest information.
|
||||
*
|
||||
* @param cfg The configuration to refresh
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_refresh(git_config *cfg);
|
||||
|
||||
/**
|
||||
* Free the configuration and its associated memory and files
|
||||
*
|
||||
|
@ -63,7 +63,6 @@ struct git_config_backend {
|
||||
int (*del)(struct git_config_backend *, const char *key);
|
||||
int (*del_multivar)(struct git_config_backend *, const char *key, const char *regexp);
|
||||
int (*iterator)(git_config_iterator **, struct git_config_backend *);
|
||||
int (*refresh)(struct git_config_backend *);
|
||||
/** Produce a read-only version of this backend */
|
||||
int (*snapshot)(struct git_config_backend **, struct git_config_backend *);
|
||||
void (*free)(struct git_config_backend *);
|
||||
|
@ -2038,8 +2038,7 @@ static int checkout_data_init(
|
||||
if ((data->opts.checkout_strategy & GIT_CHECKOUT_NO_REFRESH) == 0) {
|
||||
git_config *cfg;
|
||||
|
||||
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0 ||
|
||||
(error = git_config_refresh(cfg)) < 0)
|
||||
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* Get the repository index and reload it (unless we're checking
|
||||
|
17
src/config.c
17
src/config.c
@ -326,23 +326,6 @@ int git_config_add_backend(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int git_config_refresh(git_config *cfg)
|
||||
{
|
||||
int error = 0;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < cfg->files.length && !error; ++i) {
|
||||
file_internal *internal = git_vector_get(&cfg->files, i);
|
||||
git_config_backend *file = internal->file;
|
||||
error = file->refresh(file);
|
||||
}
|
||||
|
||||
if (!error && GIT_REFCOUNT_OWNER(cfg) != NULL)
|
||||
git_repository__cvar_cache_clear(GIT_REFCOUNT_OWNER(cfg));
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop over all the variables
|
||||
*/
|
||||
|
@ -698,7 +698,6 @@ int git_config_file__ondisk(git_config_backend **out, const char *path)
|
||||
backend->header.parent.del = config_delete;
|
||||
backend->header.parent.del_multivar = config_delete_multivar;
|
||||
backend->header.parent.iterator = config_iterator_new;
|
||||
backend->header.parent.refresh = config_refresh;
|
||||
backend->header.parent.snapshot = config_snapshot;
|
||||
backend->header.parent.free = backend_free;
|
||||
|
||||
@ -744,13 +743,6 @@ static int config_delete_readonly(git_config_backend *cfg, const char *name)
|
||||
return config_error_readonly();
|
||||
}
|
||||
|
||||
static int config_refresh_readonly(git_config_backend *cfg)
|
||||
{
|
||||
GIT_UNUSED(cfg);
|
||||
|
||||
return config_error_readonly();
|
||||
}
|
||||
|
||||
static void backend_readonly_free(git_config_backend *_backend)
|
||||
{
|
||||
diskfile_backend *backend = (diskfile_backend *)_backend;
|
||||
@ -804,7 +796,6 @@ int git_config_file__snapshot(git_config_backend **out, diskfile_backend *in)
|
||||
backend->header.parent.del = config_delete_readonly;
|
||||
backend->header.parent.del_multivar = config_delete_multivar_readonly;
|
||||
backend->header.parent.iterator = config_iterator_new;
|
||||
backend->header.parent.refresh = config_refresh_readonly;
|
||||
backend->header.parent.free = backend_readonly_free;
|
||||
|
||||
*out = (git_config_backend *)backend;
|
||||
|
@ -51,29 +51,6 @@ void test_config_include__homedir(void)
|
||||
cl_sandbox_set_search_path_defaults();
|
||||
}
|
||||
|
||||
void test_config_include__refresh(void)
|
||||
{
|
||||
git_config *cfg;
|
||||
const char *str;
|
||||
|
||||
cl_fixture_sandbox("config");
|
||||
|
||||
cl_git_pass(git_config_open_ondisk(&cfg, "config/config-include"));
|
||||
|
||||
cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
|
||||
cl_assert_equal_s(str, "huzzah");
|
||||
|
||||
/* Change the included file and see if we refresh */
|
||||
cl_git_mkfile("config/config-included", "[foo \"bar\"]\nbaz = hurrah");
|
||||
cl_git_pass(git_config_refresh(cfg));
|
||||
|
||||
cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
|
||||
cl_assert_equal_s(str, "hurrah");
|
||||
|
||||
git_config_free(cfg);
|
||||
cl_fixture_cleanup("config");
|
||||
}
|
||||
|
||||
/* We need to pretend that the variables were defined where the file was included */
|
||||
void test_config_include__ordering(void)
|
||||
{
|
||||
|
@ -1,64 +0,0 @@
|
||||
#include "clar_libgit2.h"
|
||||
|
||||
#define TEST_FILE "config.refresh"
|
||||
|
||||
void test_config_refresh__initialize(void)
|
||||
{
|
||||
}
|
||||
|
||||
void test_config_refresh__cleanup(void)
|
||||
{
|
||||
cl_fixture_cleanup(TEST_FILE);
|
||||
}
|
||||
|
||||
void test_config_refresh__update_value(void)
|
||||
{
|
||||
git_config *cfg;
|
||||
int32_t v;
|
||||
|
||||
cl_git_mkfile(TEST_FILE, "[section]\n\tvalue = 1\n\n");
|
||||
|
||||
/* By freeing the config, we make sure we flush the values */
|
||||
cl_git_pass(git_config_open_ondisk(&cfg, TEST_FILE));
|
||||
|
||||
cl_git_pass(git_config_get_int32(&v, cfg, "section.value"));
|
||||
cl_assert_equal_i(1, v);
|
||||
|
||||
cl_git_rewritefile(TEST_FILE, "[section]\n\tvalue = 10\n\n");
|
||||
|
||||
cl_git_pass(git_config_refresh(cfg));
|
||||
|
||||
cl_git_pass(git_config_get_int32(&v, cfg, "section.value"));
|
||||
cl_assert_equal_i(10, v);
|
||||
|
||||
git_config_free(cfg);
|
||||
}
|
||||
|
||||
void test_config_refresh__delete_value(void)
|
||||
{
|
||||
git_config *cfg;
|
||||
int32_t v;
|
||||
|
||||
cl_git_mkfile(TEST_FILE, "[section]\n\tvalue = 1\n\n");
|
||||
|
||||
/* By freeing the config, we make sure we flush the values */
|
||||
cl_git_pass(git_config_open_ondisk(&cfg, TEST_FILE));
|
||||
|
||||
cl_git_pass(git_config_get_int32(&v, cfg, "section.value"));
|
||||
cl_assert_equal_i(1, v);
|
||||
cl_git_fail(git_config_get_int32(&v, cfg, "section.newval"));
|
||||
|
||||
cl_git_rewritefile(TEST_FILE, "[section]\n\tnewval = 10\n\n");
|
||||
|
||||
cl_git_fail_with(GIT_ENOTFOUND, git_config_get_int32(&v, cfg, "section.value"));
|
||||
|
||||
cl_git_pass(git_config_get_int32(&v, cfg, "section.newval"));
|
||||
|
||||
cl_git_pass(git_config_refresh(cfg));
|
||||
|
||||
cl_git_fail(git_config_get_int32(&v, cfg, "section.value"));
|
||||
cl_git_pass(git_config_get_int32(&v, cfg, "section.newval"));
|
||||
cl_assert_equal_i(10, v);
|
||||
|
||||
git_config_free(cfg);
|
||||
}
|
@ -340,10 +340,5 @@ void test_config_write__outside_change(void)
|
||||
cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value"));
|
||||
cl_assert_equal_i(6, tmp);
|
||||
|
||||
cl_git_pass(git_config_refresh(cfg));
|
||||
|
||||
cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value"));
|
||||
cl_assert_equal_i(6, tmp);
|
||||
|
||||
git_config_free(cfg);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user