summaryrefslogtreecommitdiff
path: root/tests/index/tests.c
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/index/tests.c
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/index/tests.c')
-rw-r--r--tests/index/tests.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/tests/index/tests.c b/tests/index/tests.c
index d9d8371dd..9b28028e6 100644
--- a/tests/index/tests.c
+++ b/tests/index/tests.c
@@ -28,7 +28,7 @@ static struct test_entry test_entries[] = {
/* Helpers */
static void copy_file(const char *src, const char *dst)
{
- git_buf source_buf = GIT_BUF_INIT;
+ git_str source_buf = GIT_STR_INIT;
git_file dst_fd;
cl_git_pass(git_futils_readbuffer(&source_buf, src));
@@ -40,28 +40,28 @@ static void copy_file(const char *src, const char *dst)
cl_git_pass(p_write(dst_fd, source_buf.ptr, source_buf.size));
cleanup:
- git_buf_dispose(&source_buf);
+ git_str_dispose(&source_buf);
p_close(dst_fd);
}
static void files_are_equal(const char *a, const char *b)
{
- git_buf buf_a = GIT_BUF_INIT;
- git_buf buf_b = GIT_BUF_INIT;
+ git_str buf_a = GIT_STR_INIT;
+ git_str buf_b = GIT_STR_INIT;
int pass;
if (git_futils_readbuffer(&buf_a, a) < 0)
cl_assert(0);
if (git_futils_readbuffer(&buf_b, b) < 0) {
- git_buf_dispose(&buf_a);
+ git_str_dispose(&buf_a);
cl_assert(0);
}
pass = (buf_a.size == buf_b.size && !memcmp(buf_a.ptr, buf_b.ptr, buf_a.size));
- git_buf_dispose(&buf_a);
- git_buf_dispose(&buf_b);
+ git_str_dispose(&buf_a);
+ git_str_dispose(&buf_b);
cl_assert(pass);
}
@@ -544,12 +544,12 @@ void test_index_tests__add_bypath_to_a_bare_repository_returns_EBAREPO(void)
static void assert_add_bypath_fails(git_repository *repo, const char *fn)
{
git_index *index;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_repository_index(&index, repo));
cl_assert(git_index_entrycount(index) == 0);
- git_buf_joinpath(&path, "./invalid", fn);
+ git_str_joinpath(&path, "./invalid", fn);
cl_git_mkfile(path.ptr, NULL);
cl_git_fail(git_index_add_bypath(index, fn));
@@ -557,7 +557,7 @@ static void assert_add_bypath_fails(git_repository *repo, const char *fn)
cl_assert(git_index_entrycount(index) == 0);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_index_free(index);
}
@@ -592,7 +592,7 @@ void test_index_tests__cannot_add_invalid_filename(void)
static void assert_add_fails(git_repository *repo, const char *fn)
{
git_index *index;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_index_entry entry = {{0}};
cl_git_pass(git_repository_index(&index, repo));
@@ -606,7 +606,7 @@ static void assert_add_fails(git_repository *repo, const char *fn)
cl_assert(git_index_entrycount(index) == 0);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_index_free(index);
}
@@ -659,7 +659,7 @@ static void assert_write_fails(git_repository *repo, const char *fn_orig)
git_index *index;
git_oid expected;
const git_index_entry *entry;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *fn;
cl_git_pass(git_repository_index(&index, repo));
@@ -673,7 +673,7 @@ static void assert_write_fails(git_repository *repo, const char *fn_orig)
replace_char(fn, '/', '_');
replace_char(fn, ':', '!');
- git_buf_joinpath(&path, "./invalid", fn);
+ git_str_joinpath(&path, "./invalid", fn);
cl_git_mkfile(path.ptr, NULL);
@@ -691,7 +691,7 @@ static void assert_write_fails(git_repository *repo, const char *fn_orig)
p_unlink(path.ptr);
cl_git_pass(git_index_remove_all(index, NULL, NULL, NULL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_index_free(index);
git__free(fn);
}