summaryrefslogtreecommitdiff
path: root/tests/config/config_helpers.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/config/config_helpers.c
parent76f034180aee96fcc1fffd5267ccbc6ada68482a (diff)
downloadlibgit2-cmn/config-borrow-entry.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/config/config_helpers.c')
-rw-r--r--tests/config/config_helpers.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/tests/config/config_helpers.c b/tests/config/config_helpers.c
index 35da720e0..025838ad7 100644
--- a/tests/config/config_helpers.c
+++ b/tests/config/config_helpers.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "config_helpers.h"
#include "repository.h"
+#include "buffer.h"
void assert_config_entry_existence(
git_repository *repo,
@@ -8,12 +9,13 @@ void assert_config_entry_existence(
bool is_supposed_to_exist)
{
git_config *config;
- const char *out;
+ git_config_entry *entry = NULL;
int result;
cl_git_pass(git_repository_config__weakptr(&config, repo));
- result = git_config_get_string(&out, config, name);
+ result = git_config_get_entry(&entry, config, name);
+ git_config_entry_free(entry);
if (is_supposed_to_exist)
cl_git_pass(result);
@@ -27,13 +29,14 @@ void assert_config_entry_value(
const char *expected_value)
{
git_config *config;
- const char *out;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_repository_config__weakptr(&config, repo));
- cl_git_pass(git_config_get_string(&out, config, name));
+ cl_git_pass(git_config_get_string_buf(&buf, config, name));
- cl_assert_equal_s(expected_value, out);
+ cl_assert_equal_s(expected_value, git_buf_cstr(&buf));
+ git_buf_free(&buf);
}
static int count_config_entries_cb(