diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-12-21 15:31:03 +0000 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-03-03 18:35:12 +0100 |
commit | 9a97f49e3aa15edc479fc590f4b28fc44c155c40 (patch) | |
tree | b85de2d396b9d0d408f688212c0cdc74347ea7b3 /tests/refs/branches/upstream.c | |
parent | 76f034180aee96fcc1fffd5267ccbc6ada68482a (diff) | |
download | libgit2-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/refs/branches/upstream.c')
-rw-r--r-- | tests/refs/branches/upstream.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/tests/refs/branches/upstream.c b/tests/refs/branches/upstream.c index f44f563a3..351449416 100644 --- a/tests/refs/branches/upstream.c +++ b/tests/refs/branches/upstream.c @@ -1,4 +1,5 @@ #include "clar_libgit2.h" +#include "config/config_helpers.h" #include "refs.h" static git_repository *repo; @@ -123,8 +124,6 @@ void test_refs_branches_upstream__set_unset_upstream(void) { git_reference *branch; git_repository *repository; - const char *value; - git_config *config; repository = cl_git_sandbox_init("testrepo.git"); @@ -132,11 +131,8 @@ void test_refs_branches_upstream__set_unset_upstream(void) cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/test")); cl_git_pass(git_branch_set_upstream(branch, "test/master")); - cl_git_pass(git_repository_config(&config, repository)); - cl_git_pass(git_config_get_string(&value, config, "branch.test.remote")); - cl_assert_equal_s(value, "test"); - cl_git_pass(git_config_get_string(&value, config, "branch.test.merge")); - cl_assert_equal_s(value, "refs/heads/master"); + assert_config_entry_value(repository, "branch.test.remote", "test"); + assert_config_entry_value(repository, "branch.test.merge", "refs/heads/master"); git_reference_free(branch); @@ -144,25 +140,22 @@ void test_refs_branches_upstream__set_unset_upstream(void) cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/test")); cl_git_pass(git_branch_set_upstream(branch, "master")); - cl_git_pass(git_config_get_string(&value, config, "branch.test.remote")); - cl_assert_equal_s(value, "."); - cl_git_pass(git_config_get_string(&value, config, "branch.test.merge")); - cl_assert_equal_s(value, "refs/heads/master"); + assert_config_entry_value(repository, "branch.test.remote", "."); + assert_config_entry_value(repository, "branch.test.merge", "refs/heads/master"); /* unset */ cl_git_pass(git_branch_set_upstream(branch, NULL)); - cl_git_fail_with(git_config_get_string(&value, config, "branch.test.merge"), GIT_ENOTFOUND); - cl_git_fail_with(git_config_get_string(&value, config, "branch.test.remote"), GIT_ENOTFOUND); + assert_config_entry_existence(repository, "branch.test.remote", false); + assert_config_entry_existence(repository, "branch.test.merge", false); git_reference_free(branch); cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/master")); cl_git_pass(git_branch_set_upstream(branch, NULL)); - cl_git_fail_with(git_config_get_string(&value, config, "branch.master.merge"), GIT_ENOTFOUND); - cl_git_fail_with(git_config_get_string(&value, config, "branch.master.remote"), GIT_ENOTFOUND); + assert_config_entry_existence(repository, "branch.test.remote", false); + assert_config_entry_existence(repository, "branch.test.merge", false); git_reference_free(branch); - git_config_free(config); cl_git_sandbox_cleanup(); } |