From 5490c9d47036c44a255d3177f93664f4e034834b Mon Sep 17 00:00:00 2001 From: Alan Rogers Date: Thu, 16 Oct 2014 13:52:55 +1100 Subject: [PATCH 1/3] Add a test to make sure a new snapshot has the new value. --- tests/config/snapshot.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/config/snapshot.c b/tests/config/snapshot.c index c9f15921a..d8e6f4e3b 100644 --- a/tests/config/snapshot.c +++ b/tests/config/snapshot.c @@ -3,7 +3,7 @@ void test_config_snapshot__create_snapshot(void) { int32_t tmp; - git_config *cfg, *snapshot; + git_config *cfg, *snapshot, *new_snapshot; const char *filename = "config-ext-change"; cl_git_mkfile(filename, "[old]\nvalue = 5\n"); @@ -23,6 +23,19 @@ void test_config_snapshot__create_snapshot(void) cl_git_pass(git_config_get_int32(&tmp, snapshot, "old.value")); cl_assert_equal_i(5, tmp); + + /* Change the value on the file itself (simulate external process) */ + cl_git_mkfile(filename, "[old]\nvalue = 99\n"); + + cl_git_pass(git_config_snapshot(&new_snapshot, cfg)); + + /* New snapshot should see new value */ + cl_git_pass(git_config_get_int32(&tmp, new_snapshot, "old.value")); + cl_assert_equal_i(99, tmp); + + /* Old snapshot should still have the old value */ + cl_git_pass(git_config_get_int32(&tmp, snapshot, "old.value")); + cl_assert_equal_i(5, tmp); git_config_free(snapshot); git_config_free(cfg); From 1e2fe921a5fc8ad8188b69956179703f10d0a4ad Mon Sep 17 00:00:00 2001 From: Alan Rogers Date: Tue, 21 Oct 2014 09:29:17 +1100 Subject: [PATCH 2/3] Change the length of the file so that the change is picked up. --- tests/config/snapshot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/config/snapshot.c b/tests/config/snapshot.c index d8e6f4e3b..e47e252ac 100644 --- a/tests/config/snapshot.c +++ b/tests/config/snapshot.c @@ -25,13 +25,13 @@ void test_config_snapshot__create_snapshot(void) cl_assert_equal_i(5, tmp); /* Change the value on the file itself (simulate external process) */ - cl_git_mkfile(filename, "[old]\nvalue = 99\n"); + cl_git_mkfile(filename, "[old]\nvalue = 999\n"); cl_git_pass(git_config_snapshot(&new_snapshot, cfg)); /* New snapshot should see new value */ cl_git_pass(git_config_get_int32(&tmp, new_snapshot, "old.value")); - cl_assert_equal_i(99, tmp); + cl_assert_equal_i(999, tmp); /* Old snapshot should still have the old value */ cl_git_pass(git_config_get_int32(&tmp, snapshot, "old.value")); From ad5adacb1d1913620f022d7bb6c9b877ff3a4faf Mon Sep 17 00:00:00 2001 From: Alan Rogers Date: Tue, 21 Oct 2014 09:29:45 +1100 Subject: [PATCH 3/3] Patch from @carlosmn to refresh the parent config before snapshotting. --- src/config_file.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/config_file.c b/src/config_file.c index 8f55c42f3..1f73e7e11 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -767,12 +767,17 @@ static int config_readonly_open(git_config_backend *cfg, git_config_level_t leve { diskfile_readonly_backend *b = (diskfile_readonly_backend *) cfg; diskfile_backend *src = b->snapshot_from; + diskfile_header *src_header = &src->header; refcounted_strmap *src_map; + int error; + + if (!src_header->readonly && (error = config_refresh(&src_header->parent)) < 0) + return error; /* We're just copying data, don't care about the level */ GIT_UNUSED(level); - src_map = refcounted_strmap_take(&src->header); + src_map = refcounted_strmap_take(src_header); b->header.values = src_map; return 0;