summaryrefslogtreecommitdiff
path: root/tests/worktree
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-09-07 17:53:49 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-10-17 09:49:01 -0400
commitf0e693b18afbe1de37d7da5b5a8967b6c87d8e53 (patch)
treebe5e1cdbfa218ba81ec06bf45e45cfeb7f79a2a5 /tests/worktree
parent5346be3ddd3bcf19779c5d62e71f8442a0171133 (diff)
downloadlibgit2-ethomson/gitstr.tar.gz
str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstr
libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
Diffstat (limited to 'tests/worktree')
-rw-r--r--tests/worktree/merge.c14
-rw-r--r--tests/worktree/open.c10
-rw-r--r--tests/worktree/refs.c6
-rw-r--r--tests/worktree/submodule.c6
-rw-r--r--tests/worktree/worktree.c102
5 files changed, 69 insertions, 69 deletions
diff --git a/tests/worktree/merge.c b/tests/worktree/merge.c
index 2a1206032..8bb95d1f7 100644
--- a/tests/worktree/merge.c
+++ b/tests/worktree/merge.c
@@ -57,7 +57,7 @@ void test_worktree_merge__merge_setup(void)
{
git_reference *ours_ref, *theirs_ref;
git_annotated_commit *ours, *theirs;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
unsigned i;
cl_git_pass(git_reference_lookup(&ours_ref, fixture.worktree, MASTER_BRANCH));
@@ -70,13 +70,13 @@ void test_worktree_merge__merge_setup(void)
ours, (const git_annotated_commit **)&theirs, 1));
for (i = 0; i < ARRAY_SIZE(merge_files); i++) {
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_joinpath(&path,
fixture.worktree->gitdir,
merge_files[i]));
cl_assert(git_path_exists(path.ptr));
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_reference_free(ours_ref);
git_reference_free(theirs_ref);
git_annotated_commit_free(ours);
@@ -85,7 +85,7 @@ void test_worktree_merge__merge_setup(void)
void test_worktree_merge__merge_conflict(void)
{
- git_buf path = GIT_BUF_INIT, buf = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, buf = GIT_STR_INIT;
git_reference *theirs_ref;
git_annotated_commit *theirs;
git_index *index;
@@ -111,11 +111,11 @@ void test_worktree_merge__merge_conflict(void)
git_annotated_commit_free(theirs);
git_index_free(index);
- cl_git_pass(git_buf_joinpath(&path, fixture.worktree->workdir, "branch_file.txt"));
+ cl_git_pass(git_str_joinpath(&path, fixture.worktree->workdir, "branch_file.txt"));
cl_git_pass(git_futils_readbuffer(&buf, path.ptr));
cl_assert_equal_s(buf.ptr, CONFLICT_BRANCH_FILE_TXT);
- git_buf_dispose(&path);
- git_buf_dispose(&buf);
+ git_str_dispose(&path);
+ git_str_dispose(&buf);
}
diff --git a/tests/worktree/open.c b/tests/worktree/open.c
index 52d47334c..0c3fdc173 100644
--- a/tests/worktree/open.c
+++ b/tests/worktree/open.c
@@ -55,17 +55,17 @@ void test_worktree_open__repository_through_gitlink(void)
void test_worktree_open__repository_through_gitdir(void)
{
- git_buf gitdir_path = GIT_BUF_INIT;
+ git_str gitdir_path = GIT_STR_INIT;
git_repository *wt;
- cl_git_pass(git_buf_joinpath(&gitdir_path, COMMON_REPO, ".git"));
- cl_git_pass(git_buf_joinpath(&gitdir_path, gitdir_path.ptr, "worktrees"));
- cl_git_pass(git_buf_joinpath(&gitdir_path, gitdir_path.ptr, "testrepo-worktree"));
+ cl_git_pass(git_str_joinpath(&gitdir_path, COMMON_REPO, ".git"));
+ cl_git_pass(git_str_joinpath(&gitdir_path, gitdir_path.ptr, "worktrees"));
+ cl_git_pass(git_str_joinpath(&gitdir_path, gitdir_path.ptr, "testrepo-worktree"));
cl_git_pass(git_repository_open(&wt, gitdir_path.ptr));
assert_worktree_valid(wt, COMMON_REPO, WORKTREE_REPO);
- git_buf_dispose(&gitdir_path);
+ git_str_dispose(&gitdir_path);
git_repository_free(wt);
}
diff --git a/tests/worktree/refs.c b/tests/worktree/refs.c
index 27dc667ea..5ae17ca19 100644
--- a/tests/worktree/refs.c
+++ b/tests/worktree/refs.c
@@ -177,9 +177,9 @@ void test_worktree_refs__creating_refs_uses_commondir(void)
{
git_reference *head, *branch, *lookup;
git_commit *commit;
- git_buf refpath = GIT_BUF_INIT;
+ git_str refpath = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&refpath,
+ cl_git_pass(git_str_joinpath(&refpath,
git_repository_commondir(fixture.worktree), "refs/heads/testbranch"));
cl_assert(!git_path_exists(refpath.ptr));
@@ -194,5 +194,5 @@ void test_worktree_refs__creating_refs_uses_commondir(void)
git_reference_free(branch);
git_reference_free(head);
git_commit_free(commit);
- git_buf_dispose(&refpath);
+ git_str_dispose(&refpath);
}
diff --git a/tests/worktree/submodule.c b/tests/worktree/submodule.c
index 2e62c039c..4c6c657d3 100644
--- a/tests/worktree/submodule.c
+++ b/tests/worktree/submodule.c
@@ -61,14 +61,14 @@ void test_worktree_submodule__open_discovered_submodule_worktree(void)
void test_worktree_submodule__resolve_relative_url(void)
{
- git_buf wt_path = GIT_BUF_INIT;
+ git_str wt_path = GIT_STR_INIT;
git_buf sm_relative_path = GIT_BUF_INIT, wt_relative_path = GIT_BUF_INIT;
git_repository *repo;
git_worktree *wt;
cl_git_pass(git_futils_mkdir("subdir", 0755, GIT_MKDIR_PATH));
cl_git_pass(git_path_prettify_dir(&wt_path, "subdir", NULL));
- cl_git_pass(git_buf_joinpath(&wt_path, wt_path.ptr, "wt"));
+ cl_git_pass(git_str_joinpath(&wt_path, wt_path.ptr, "wt"));
/* Open child repository, which is a submodule */
cl_git_pass(git_repository_open(&child.repo, WORKTREE_CHILD));
@@ -86,7 +86,7 @@ void test_worktree_submodule__resolve_relative_url(void)
git_worktree_free(wt);
git_repository_free(repo);
- git_buf_dispose(&wt_path);
+ git_str_dispose(&wt_path);
git_buf_dispose(&sm_relative_path);
git_buf_dispose(&wt_relative_path);
}
diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c
index 9b87bfae6..a9a50fbf1 100644
--- a/tests/worktree/worktree.c
+++ b/tests/worktree/worktree.c
@@ -40,11 +40,11 @@ void test_worktree_worktree__list_with_invalid_worktree_dirs(void)
{ "gitdir", "HEAD" },
{ "HEAD", "commondir" },
};
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_strarray wts;
size_t i, j, len;
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_joinpath(&path,
fixture.repo->commondir,
"worktrees/invalid"));
cl_git_pass(p_mkdir(path.ptr, 0755));
@@ -54,8 +54,8 @@ void test_worktree_worktree__list_with_invalid_worktree_dirs(void)
for (i = 0; i < ARRAY_SIZE(filesets); i++) {
for (j = 0; j < ARRAY_SIZE(filesets[i]); j++) {
- git_buf_truncate(&path, len);
- cl_git_pass(git_buf_joinpath(&path, path.ptr, filesets[i][j]));
+ git_str_truncate(&path, len);
+ cl_git_pass(git_str_joinpath(&path, path.ptr, filesets[i][j]));
cl_git_pass(p_close(p_creat(path.ptr, 0644)));
}
@@ -65,13 +65,13 @@ void test_worktree_worktree__list_with_invalid_worktree_dirs(void)
git_strarray_dispose(&wts);
for (j = 0; j < ARRAY_SIZE(filesets[i]); j++) {
- git_buf_truncate(&path, len);
- cl_git_pass(git_buf_joinpath(&path, path.ptr, filesets[i][j]));
+ git_str_truncate(&path, len);
+ cl_git_pass(git_str_joinpath(&path, path.ptr, filesets[i][j]));
p_unlink(path.ptr);
}
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_worktree_worktree__list_in_worktree_repo(void)
@@ -100,11 +100,11 @@ void test_worktree_worktree__list_without_worktrees(void)
void test_worktree_worktree__lookup(void)
{
git_worktree *wt;
- git_buf gitdir_path = GIT_BUF_INIT;
+ git_str gitdir_path = GIT_STR_INIT;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
- cl_git_pass(git_buf_joinpath(&gitdir_path, fixture.repo->commondir, "worktrees/testrepo-worktree/"));
+ cl_git_pass(git_str_joinpath(&gitdir_path, fixture.repo->commondir, "worktrees/testrepo-worktree/"));
cl_assert_equal_s(wt->gitdir_path, gitdir_path.ptr);
cl_assert_equal_s(wt->parent_path, fixture.repo->workdir);
@@ -112,7 +112,7 @@ void test_worktree_worktree__lookup(void)
cl_assert_equal_s(wt->commondir_path, fixture.repo->gitdir);
cl_assert_equal_s(wt->commondir_path, fixture.repo->commondir);
- git_buf_dispose(&gitdir_path);
+ git_str_dispose(&gitdir_path);
git_worktree_free(wt);
}
@@ -143,10 +143,10 @@ void test_worktree_worktree__open_invalid_commondir(void)
{
git_worktree *wt;
git_repository *repo;
- git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/commondir"));
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_sets(&buf, "/path/to/nonexistent/commondir"));
+ cl_git_pass(git_str_joinpath(&path,
fixture.repo->commondir,
"worktrees/testrepo-worktree/commondir"));
cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
@@ -154,8 +154,8 @@ void test_worktree_worktree__open_invalid_commondir(void)
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
- git_buf_dispose(&buf);
- git_buf_dispose(&path);
+ git_str_dispose(&buf);
+ git_str_dispose(&path);
git_worktree_free(wt);
}
@@ -163,10 +163,10 @@ void test_worktree_worktree__open_invalid_gitdir(void)
{
git_worktree *wt;
git_repository *repo;
- git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/gitdir"));
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_sets(&buf, "/path/to/nonexistent/gitdir"));
+ cl_git_pass(git_str_joinpath(&path,
fixture.repo->commondir,
"worktrees/testrepo-worktree/gitdir"));
cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
@@ -174,8 +174,8 @@ void test_worktree_worktree__open_invalid_gitdir(void)
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
- git_buf_dispose(&buf);
- git_buf_dispose(&path);
+ git_str_dispose(&buf);
+ git_str_dispose(&path);
git_worktree_free(wt);
}
@@ -183,16 +183,16 @@ void test_worktree_worktree__open_invalid_parent(void)
{
git_worktree *wt;
git_repository *repo;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/gitdir"));
+ cl_git_pass(git_str_sets(&buf, "/path/to/nonexistent/gitdir"));
cl_git_pass(git_futils_writebuffer(&buf,
fixture.worktree->gitlink, O_RDWR, 0644));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_worktree_free(wt);
}
@@ -201,9 +201,9 @@ void test_worktree_worktree__init(void)
git_worktree *wt;
git_repository *repo;
git_reference *branch;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
/* Open and verify created repo */
@@ -211,7 +211,7 @@ void test_worktree_worktree__init(void)
cl_assert(git__suffixcmp(git_repository_workdir(repo), "worktree-new/") == 0);
cl_git_pass(git_branch_lookup(&branch, repo, "worktree-new", GIT_BRANCH_LOCAL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_worktree_free(wt);
git_reference_free(branch);
git_repository_free(repo);
@@ -222,12 +222,12 @@ void test_worktree_worktree__add_locked(void)
git_worktree *wt;
git_repository *repo;
git_reference *branch;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
opts.lock = 1;
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-locked"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-locked"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-locked", path.ptr, &opts));
/* Open and verify created repo */
@@ -236,7 +236,7 @@ void test_worktree_worktree__add_locked(void)
cl_assert(git__suffixcmp(git_repository_workdir(repo), "worktree-locked/") == 0);
cl_git_pass(git_branch_lookup(&branch, repo, "worktree-locked", GIT_BRANCH_LOCAL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_worktree_free(wt);
git_reference_free(branch);
git_repository_free(repo);
@@ -247,16 +247,16 @@ void test_worktree_worktree__init_existing_branch(void)
git_reference *head, *branch;
git_commit *commit;
git_worktree *wt;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_repository_head(&head, fixture.repo));
cl_git_pass(git_commit_lookup(&commit, fixture.repo, &head->target.oid));
cl_git_pass(git_branch_create(&branch, fixture.repo, "worktree-new", commit, false));
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_commit_free(commit);
git_reference_free(head);
git_reference_free(branch);
@@ -268,7 +268,7 @@ void test_worktree_worktree__add_with_explicit_branch(void)
git_commit *commit;
git_worktree *wt;
git_repository *wtrepo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
cl_git_pass(git_repository_head(&head, fixture.repo));
@@ -277,13 +277,13 @@ void test_worktree_worktree__add_with_explicit_branch(void)
opts.ref = branch;
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-with-different-name"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-with-different-name"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-with-different-name", path.ptr, &opts));
cl_git_pass(git_repository_open_from_worktree(&wtrepo, wt));
cl_git_pass(git_repository_head(&wthead, wtrepo));
cl_assert_equal_s(git_reference_name(wthead), "refs/heads/worktree-with-ref");
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_commit_free(commit);
git_reference_free(head);
git_reference_free(branch);
@@ -296,15 +296,15 @@ void test_worktree_worktree__add_with_explicit_branch(void)
void test_worktree_worktree__init_existing_worktree(void)
{
git_worktree *wt;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
cl_git_fail(git_worktree_add(&wt, fixture.repo, "testrepo-worktree", path.ptr, NULL));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->gitlink);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_worktree_free(wt);
}
@@ -312,42 +312,42 @@ void test_worktree_worktree__init_existing_path(void)
{
const char *wtfiles[] = { "HEAD", "commondir", "gitdir", "index" };
git_worktree *wt;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
unsigned i;
/* Delete files to verify they have not been created by
* the init call */
for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_joinpath(&path,
fixture.worktree->gitdir, wtfiles[i]));
cl_git_pass(p_unlink(path.ptr));
}
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../testrepo-worktree"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../testrepo-worktree"));
cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
/* Verify files have not been re-created */
for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_joinpath(&path,
fixture.worktree->gitdir, wtfiles[i]));
cl_assert(!git_path_exists(path.ptr));
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_worktree_worktree__init_submodule(void)
{
git_repository *repo, *sm, *wt;
git_worktree *worktree;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cleanup_fixture_worktree(&fixture);
repo = setup_fixture_submod2();
- cl_git_pass(git_buf_joinpath(&path, repo->workdir, "sm_unchanged"));
+ cl_git_pass(git_str_joinpath(&path, repo->workdir, "sm_unchanged"));
cl_git_pass(git_repository_open(&sm, path.ptr));
- cl_git_pass(git_buf_joinpath(&path, repo->workdir, "../worktree/"));
+ cl_git_pass(git_str_joinpath(&path, repo->workdir, "../worktree/"));
cl_git_pass(git_worktree_add(&worktree, sm, "repo-worktree", path.ptr, NULL));
cl_git_pass(git_repository_open_from_worktree(&wt, worktree));
@@ -356,10 +356,10 @@ void test_worktree_worktree__init_submodule(void)
cl_git_pass(git_path_prettify_dir(&path, sm->commondir, NULL));
cl_assert_equal_s(sm->commondir, wt->commondir);
- cl_git_pass(git_buf_joinpath(&path, sm->gitdir, "worktrees/repo-worktree/"));
+ cl_git_pass(git_str_joinpath(&path, sm->gitdir, "worktrees/repo-worktree/"));
cl_assert_equal_s(path.ptr, wt->gitdir);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_worktree_free(worktree);
git_repository_free(sm);
git_repository_free(wt);
@@ -388,13 +388,13 @@ void test_worktree_worktree__name(void)
void test_worktree_worktree__path(void)
{
git_worktree *wt;
- git_buf expected_path = GIT_BUF_INIT;
+ git_str expected_path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&expected_path, clar_sandbox_path(), "testrepo-worktree"));
+ cl_git_pass(git_str_joinpath(&expected_path, clar_sandbox_path(), "testrepo-worktree"));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert_equal_s(git_worktree_path(wt), expected_path.ptr);
- git_buf_dispose(&expected_path);
+ git_str_dispose(&expected_path);
git_worktree_free(wt);
}