Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-12-21 18:31:03 +0300
committerCarlos Martín Nieto <cmn@dwim.me>2015-03-03 20:35:12 +0300
commit9a97f49e3aa15edc479fc590f4b28fc44c155c40 (patch)
treeb85de2d396b9d0d408f688212c0cdc74347ea7b3 /tests/repo
parent76f034180aee96fcc1fffd5267ccbc6ada68482a (diff)
config: borrow refcounted references
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/repo')
-rw-r--r--tests/repo/init.c15
-rw-r--r--tests/repo/setters.c8
2 files changed, 8 insertions, 15 deletions
diff --git a/tests/repo/init.c b/tests/repo/init.c
index 076156817..525020f5a 100644
--- a/tests/repo/init.c
+++ b/tests/repo/init.c
@@ -3,6 +3,7 @@
#include "repository.h"
#include "config.h"
#include "path.h"
+#include "config/config_helpers.h"
enum repo_mode {
STANDARD_REPOSITORY = 0,
@@ -370,8 +371,6 @@ void test_repo_init__extended_1(void)
void test_repo_init__relative_gitdir(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_config *cfg;
- const char *worktree_path;
git_buf dot_git_content = GIT_BUF_INIT;
opts.workdir_path = "../c_wd";
@@ -391,24 +390,19 @@ void test_repo_init__relative_gitdir(void)
/* Verify that the gitlink and worktree entries are relative */
/* Verify worktree */
- cl_git_pass(git_repository_config(&cfg, _repo));
- cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree"));
- cl_assert_equal_s("../c_wd/", worktree_path);
+ assert_config_entry_value(_repo, "core.worktree", "../c_wd/");
/* Verify gitlink */
cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
git_buf_free(&dot_git_content);
- git_config_free(cfg);
cleanup_repository("root");
}
void test_repo_init__relative_gitdir_2(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_config *cfg;
- const char *worktree_path;
git_buf dot_git_content = GIT_BUF_INIT;
git_buf full_path = GIT_BUF_INIT;
@@ -433,16 +427,13 @@ void test_repo_init__relative_gitdir_2(void)
/* Verify that the gitlink and worktree entries are relative */
/* Verify worktree */
- cl_git_pass(git_repository_config(&cfg, _repo));
- cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree"));
- cl_assert_equal_s("../c_wd/", worktree_path);
+ assert_config_entry_value(_repo, "core.worktree", "../c_wd/");
/* Verify gitlink */
cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
git_buf_free(&dot_git_content);
- git_config_free(cfg);
cleanup_repository("root");
}
diff --git a/tests/repo/setters.c b/tests/repo/setters.c
index f34f1e471..5a83fdbee 100644
--- a/tests/repo/setters.c
+++ b/tests/repo/setters.c
@@ -46,7 +46,7 @@ void test_repo_setters__setting_a_workdir_prettifies_its_path(void)
void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
{
git_config *cfg;
- const char *val;
+ git_buf buf = GIT_BUF_INIT;
git_buf content = GIT_BUF_INIT;
cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", true));
@@ -59,8 +59,10 @@ void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
git_buf_free(&content);
cl_git_pass(git_repository_config(&cfg, repo));
- cl_git_pass(git_config_get_string(&val, cfg, "core.worktree"));
- cl_assert(git__suffixcmp(val, "new_workdir/") == 0);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.worktree"));
+ cl_assert(git__suffixcmp(git_buf_cstr(&buf), "new_workdir/") == 0);
+
+ git_buf_free(&buf);
git_config_free(cfg);
}