summaryrefslogtreecommitdiff
path: root/tests/config/write.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-06-01 20:02:23 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-08-12 04:09:38 +0200
commit36f784b538c4b27f7b52427d2cfce06c535abba0 (patch)
treecea0d9dd8e9807e30583ba54c5aa2e58c6c14fe2 /tests/config/write.c
parentb1667039640ba3464ea0e2d13ad28c9244d80b4d (diff)
downloadlibgit2-36f784b538c4b27f7b52427d2cfce06c535abba0.tar.gz
config: expose locking via the main API
This lock/unlock pair allows for the cller to lock a configuration file to avoid concurrent operations. It also allows for a transactional approach to updating a configuration file. If multiple updates must be made atomically, they can be done while the config is locked.
Diffstat (limited to 'tests/config/write.c')
-rw-r--r--tests/config/write.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/tests/config/write.c b/tests/config/write.c
index 5446b95c3..e43c26bd9 100644
--- a/tests/config/write.c
+++ b/tests/config/write.c
@@ -635,44 +635,47 @@ void test_config_write__to_file_with_only_comment(void)
void test_config_write__locking(void)
{
- git_config_backend *cfg, *cfg2;
+ git_config *cfg, *cfg2;
git_config_entry *entry;
const char *filename = "locked-file";
/* Open the config and lock it */
cl_git_mkfile(filename, "[section]\n\tname = value\n");
- cl_git_pass(git_config_file__ondisk(&cfg, filename));
- cl_git_pass(git_config_file_open(cfg, GIT_CONFIG_LEVEL_APP));
- cl_git_pass(git_config_file_get_string(&entry, cfg, "section.name"));
+ cl_git_pass(git_config_open_ondisk(&cfg, filename));
+ cl_git_pass(git_config_get_entry(&entry, cfg, "section.name"));
cl_assert_equal_s("value", entry->value);
git_config_entry_free(entry);
- cl_git_pass(git_config_file_lock(cfg));
+ cl_git_pass(git_config_lock(cfg));
/* Change entries in the locked backend */
- cl_git_pass(git_config_file_set_string(cfg, "section.name", "other value"));
- cl_git_pass(git_config_file_set_string(cfg, "section2.name3", "more value"));
+ cl_git_pass(git_config_set_string(cfg, "section.name", "other value"));
+ cl_git_pass(git_config_set_string(cfg, "section2.name3", "more value"));
/* We can see that the file we read from hasn't changed */
- cl_git_pass(git_config_file__ondisk(&cfg2, filename));
- cl_git_pass(git_config_file_open(cfg2, GIT_CONFIG_LEVEL_APP));
- cl_git_pass(git_config_file_get_string(&entry, cfg2, "section.name"));
+ cl_git_pass(git_config_open_ondisk(&cfg2, filename));
+ cl_git_pass(git_config_get_entry(&entry, cfg2, "section.name"));
cl_assert_equal_s("value", entry->value);
git_config_entry_free(entry);
- cl_git_fail_with(GIT_ENOTFOUND, git_config_file_get_string(&entry, cfg2, "section2.name3"));
- git_config_file_free(cfg2);
+ cl_git_fail_with(GIT_ENOTFOUND, git_config_get_entry(&entry, cfg2, "section2.name3"));
+ git_config_free(cfg2);
- git_config_file_unlock(cfg, true);
- git_config_file_free(cfg);
+ /* And we also get the old view when we read from the locked config */
+ cl_git_pass(git_config_get_entry(&entry, cfg, "section.name"));
+ cl_assert_equal_s("value", entry->value);
+ git_config_entry_free(entry);
+ cl_git_fail_with(GIT_ENOTFOUND, git_config_get_entry(&entry, cfg, "section2.name3"));
+
+ git_config_unlock(cfg, true);
+ git_config_free(cfg);
/* Now that we've unlocked it, we should see both updates */
- cl_git_pass(git_config_file__ondisk(&cfg, filename));
- cl_git_pass(git_config_file_open(cfg, GIT_CONFIG_LEVEL_APP));
- cl_git_pass(git_config_file_get_string(&entry, cfg, "section.name"));
+ cl_git_pass(git_config_open_ondisk(&cfg, filename));
+ cl_git_pass(git_config_get_entry(&entry, cfg, "section.name"));
cl_assert_equal_s("other value", entry->value);
git_config_entry_free(entry);
- cl_git_pass(git_config_file_get_string(&entry, cfg, "section2.name3"));
+ cl_git_pass(git_config_get_entry(&entry, cfg, "section2.name3"));
cl_assert_equal_s("more value", entry->value);
git_config_entry_free(entry);
- git_config_file_free(cfg);
+ git_config_free(cfg);
}