summaryrefslogtreecommitdiff
path: root/tests/iterator
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-09-07 17:53:49 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-09-30 12:42:46 -0400
commitfe07fa64878f3b7dfc7ed2964c3d45fd2fd6be7f (patch)
tree62db77db4f4486766d7d5f3bb6a12a85ec305ce9 /tests/iterator
parentcb2c926336f5f7f1a75c871cb74d567b52bb8c5c (diff)
downloadlibgit2-fe07fa64878f3b7dfc7ed2964c3d45fd2fd6be7f.tar.gz
str: introduce `git_str` for internal, `git_buf` is external
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/iterator')
-rw-r--r--tests/iterator/index.c18
-rw-r--r--tests/iterator/tree.c6
-rw-r--r--tests/iterator/workdir.c18
3 files changed, 21 insertions, 21 deletions
diff --git a/tests/iterator/index.c b/tests/iterator/index.c
index 25d8c2990..69b795f5c 100644
--- a/tests/iterator/index.c
+++ b/tests/iterator/index.c
@@ -279,12 +279,12 @@ static const char *expected_index_ci[] = {
void test_iterator_index__case_folding(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int fs_is_ci = 0;
- cl_git_pass(git_buf_joinpath(&path, cl_fixture("icase"), ".gitted/CoNfIg"));
+ cl_git_pass(git_str_joinpath(&path, cl_fixture("icase"), ".gitted/CoNfIg"));
fs_is_ci = git_path_exists(path.ptr);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
index_iterator_test(
"icase", NULL, NULL, 0, ARRAY_SIZE(expected_index_cs),
@@ -978,22 +978,22 @@ void test_iterator_index__pathlist_with_directory(void)
static void create_paths(git_index *index, const char *root, int depth)
{
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
git_index_entry entry;
size_t root_len;
int i;
if (root) {
- cl_git_pass(git_buf_puts(&fullpath, root));
- cl_git_pass(git_buf_putc(&fullpath, '/'));
+ cl_git_pass(git_str_puts(&fullpath, root));
+ cl_git_pass(git_str_putc(&fullpath, '/'));
}
root_len = fullpath.size;
for (i = 0; i < 8; i++) {
bool file = (depth == 0 || (i % 2) == 0);
- git_buf_truncate(&fullpath, root_len);
- cl_git_pass(git_buf_printf(&fullpath, "item%d", i));
+ git_str_truncate(&fullpath, root_len);
+ cl_git_pass(git_str_printf(&fullpath, "item%d", i));
if (file) {
memset(&entry, 0, sizeof(git_index_entry));
@@ -1007,7 +1007,7 @@ static void create_paths(git_index *index, const char *root, int depth)
}
}
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
}
void test_iterator_index__pathlist_for_deeply_nested_item(void)
diff --git a/tests/iterator/tree.c b/tests/iterator/tree.c
index f7fb9a7ee..4145c8dea 100644
--- a/tests/iterator/tree.c
+++ b/tests/iterator/tree.c
@@ -623,7 +623,7 @@ static void build_test_tree(
const char *scan = fmt, *next;
char type, delimiter;
git_filemode_t mode = GIT_FILEMODE_BLOB;
- git_buf name = GIT_BUF_INIT;
+ git_str name = GIT_STR_INIT;
va_list arglist;
cl_git_pass(git_treebuilder_new(&builder, repo, NULL)); /* start builder */
@@ -640,7 +640,7 @@ static void build_test_tree(
delimiter = *scan++; /* read and skip delimiter */
for (next = scan; *next && *next != delimiter; ++next)
/* seek end */;
- cl_git_pass(git_buf_set(&name, scan, (size_t)(next - scan)));
+ cl_git_pass(git_str_set(&name, scan, (size_t)(next - scan)));
for (scan = next; *scan && (*scan == delimiter || *scan == ','); ++scan)
/* skip delimiter and optional comma */;
@@ -653,7 +653,7 @@ static void build_test_tree(
cl_git_pass(git_treebuilder_write(out, builder));
git_treebuilder_free(builder);
- git_buf_dispose(&name);
+ git_str_dispose(&name);
}
void test_iterator_tree__case_conflicts_0(void)
diff --git a/tests/iterator/workdir.c b/tests/iterator/workdir.c
index 82ee363f9..7ca726c24 100644
--- a/tests/iterator/workdir.c
+++ b/tests/iterator/workdir.c
@@ -643,7 +643,7 @@ void test_iterator_workdir__filesystem2(void)
*/
void test_iterator_workdir__filesystem_gunk(void)
{
- git_buf parent = GIT_BUF_INIT;
+ git_str parent = GIT_STR_INIT;
git_iterator *i;
int n;
@@ -653,8 +653,8 @@ void test_iterator_workdir__filesystem_gunk(void)
g_repo = cl_git_sandbox_init("testrepo");
for (n = 0; n < 100000; n++) {
- git_buf_clear(&parent);
- cl_git_pass(git_buf_printf(&parent, "%s/refs/heads/foo/%d/subdir", git_repository_path(g_repo), n));
+ git_str_clear(&parent);
+ cl_git_pass(git_str_printf(&parent, "%s/refs/heads/foo/%d/subdir", git_repository_path(g_repo), n));
cl_git_pass(git_futils_mkdir(parent.ptr, 0775, GIT_MKDIR_PATH));
}
@@ -667,7 +667,7 @@ void test_iterator_workdir__filesystem_gunk(void)
expect_iterator_items(i, 17, NULL, 16, NULL);
git_iterator_free(i);
- git_buf_dispose(&parent);
+ git_str_dispose(&parent);
}
void test_iterator_workdir__skips_unreadable_dirs(void)
@@ -1019,19 +1019,19 @@ void test_iterator_workdir__pathlist_with_dirs(void)
static void create_paths(const char *root, int depth)
{
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
size_t root_len;
int i;
- cl_git_pass(git_buf_puts(&fullpath, root));
+ cl_git_pass(git_str_puts(&fullpath, root));
cl_git_pass(git_path_to_dir(&fullpath));
root_len = fullpath.size;
for (i = 0; i < 8; i++) {
bool file = (depth == 0 || (i % 2) == 0);
- git_buf_truncate(&fullpath, root_len);
- cl_git_pass(git_buf_printf(&fullpath, "item%d", i));
+ git_str_truncate(&fullpath, root_len);
+ cl_git_pass(git_str_printf(&fullpath, "item%d", i));
if (file) {
cl_git_rewritefile(fullpath.ptr, "This is a file!\n");
@@ -1043,7 +1043,7 @@ static void create_paths(const char *root, int depth)
}
}
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
}
void test_iterator_workdir__pathlist_for_deeply_nested_item(void)