summaryrefslogtreecommitdiff
path: root/tests/submodule/modify.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-12-21 15:31:03 +0000
committerCarlos Martín Nieto <cmn@dwim.me>2015-03-03 18:35:12 +0100
commit9a97f49e3aa15edc479fc590f4b28fc44c155c40 (patch)
treeb85de2d396b9d0d408f688212c0cdc74347ea7b3 /tests/submodule/modify.c
parent76f034180aee96fcc1fffd5267ccbc6ada68482a (diff)
downloadlibgit2-9a97f49e3aa15edc479fc590f4b28fc44c155c40.tar.gz
config: borrow refcounted referencescmn/config-borrow-entry
This changes the get_entry() method to return a refcounted version of the config entry, which you have to free when you're done. This allows us to avoid freeing the memory in which the entry is stored on a refresh, which may happen at any time for a live config. For this reason, get_string() has been forbidden on live configs and a new function get_string_buf() has been added, which stores the string in a git_buf which the user then owns. The functions which parse the string value takea advantage of the borrowing to parse safely and then release the entry.
Diffstat (limited to 'tests/submodule/modify.c')
-rw-r--r--tests/submodule/modify.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/tests/submodule/modify.c b/tests/submodule/modify.c
index 9bb48bad2..3d7269bff 100644
--- a/tests/submodule/modify.c
+++ b/tests/submodule/modify.c
@@ -2,6 +2,7 @@
#include "posix.h"
#include "path.h"
#include "submodule_helpers.h"
+#include "config/config_helpers.h"
static git_repository *g_repo = NULL;
@@ -51,7 +52,7 @@ void test_submodule_modify__init(void)
git_submodule_reload_all(g_repo, 1);
/* confirm submodule data in config */
- cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));
cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_unchanged.url"));
cl_assert(git__suffixcmp(str, "/submod2_target") == 0);
cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_changed_head.url"));
@@ -72,20 +73,12 @@ static int sync_one_submodule(
static void assert_submodule_url_is_synced(
git_submodule *sm, const char *parent_key, const char *child_key)
{
- git_config *cfg;
- const char *str;
git_repository *smrepo;
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(git_config_get_string(&str, cfg, parent_key));
- cl_assert_equal_s(git_submodule_url(sm), str);
- git_config_free(cfg);
+ assert_config_entry_value(g_repo, parent_key, git_submodule_url(sm));
cl_git_pass(git_submodule_open(&smrepo, sm));
- cl_git_pass(git_repository_config(&cfg, smrepo));
- cl_git_pass(git_config_get_string(&str, cfg, child_key));
- cl_assert_equal_s(git_submodule_url(sm), str);
- git_config_free(cfg);
+ assert_config_entry_value(smrepo, child_key, git_submodule_url(sm));
git_repository_free(smrepo);
}
@@ -111,7 +104,7 @@ void test_submodule_modify__sync(void)
*/
/* check submodule info does not match before sync */
- cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));
cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM1".url"));
cl_assert(strcmp(git_submodule_url(sm1), str) != 0);
cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM2".url"));