mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 13:04:42 +00:00
config: refresh included files
We need to refresh the variables from the included files if they are changed, so loop over all included files and re-parse the files if any of them has changed.
This commit is contained in:
parent
19be0692b4
commit
a9fb79896e
@ -197,14 +197,25 @@ static int config_open(git_config_backend *cfg, git_config_level_t level)
|
||||
|
||||
static int config_refresh(git_config_backend *cfg)
|
||||
{
|
||||
int res, updated = 0;
|
||||
int res = 0, updated = 0, any_updated = 0;
|
||||
diskfile_backend *b = (diskfile_backend *)cfg;
|
||||
git_strmap *old_values;
|
||||
struct reader *reader = git_array_get(b->readers, 0);
|
||||
struct reader *reader;
|
||||
uint32_t i;
|
||||
|
||||
res = git_futils_readbuffer_updated(
|
||||
&reader->buffer, b->file_path, &reader->file_mtime, &reader->file_size, &updated);
|
||||
if (res < 0 || !updated)
|
||||
for (i = 0; i < git_array_size(b->readers); i++) {
|
||||
reader = git_array_get(b->readers, i);
|
||||
res = git_futils_readbuffer_updated(
|
||||
&reader->buffer, reader->file_path, &reader->file_mtime, &reader->file_size, &updated);
|
||||
|
||||
if (res < 0)
|
||||
return (res == GIT_ENOTFOUND) ? 0 : res;
|
||||
|
||||
if (updated)
|
||||
any_updated = 1;
|
||||
}
|
||||
|
||||
if (!any_updated)
|
||||
return (res == GIT_ENOTFOUND) ? 0 : res;
|
||||
|
||||
/* need to reload - store old values and prep for reload */
|
||||
|
@ -48,3 +48,26 @@ void test_config_include__homedir(void)
|
||||
|
||||
git_config_free(cfg);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user