diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2021-09-07 17:53:49 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2021-10-17 09:49:01 -0400 |
commit | f0e693b18afbe1de37d7da5b5a8967b6c87d8e53 (patch) | |
tree | be5e1cdbfa218ba81ec06bf45e45cfeb7f79a2a5 /tests/core/env.c | |
parent | 5346be3ddd3bcf19779c5d62e71f8442a0171133 (diff) | |
download | libgit2-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/core/env.c')
-rw-r--r-- | tests/core/env.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/tests/core/env.c b/tests/core/env.c index 3c34b2c4d..9a3f0ae76 100644 --- a/tests/core/env.c +++ b/tests/core/env.c @@ -83,7 +83,7 @@ static void setenv_and_check(const char *name, const char *value) void test_core_env__0(void) { - git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT; + git_str path = GIT_STR_INIT, found = GIT_STR_INIT; char testfile[16], tidx = '0'; char **val; const char *testname = "testfile"; @@ -110,9 +110,9 @@ void test_core_env__0(void) * accidentally make this test pass... */ testfile[testlen] = tidx++; - cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile)); + cl_git_pass(git_str_joinpath(&path, path.ptr, testfile)); cl_git_mkfile(path.ptr, "find me"); - git_buf_rtruncate_at_char(&path, '/'); + git_str_rtruncate_at_char(&path, '/'); cl_assert_equal_i( GIT_ENOTFOUND, git_sysdir_find_global_file(&found, testfile)); @@ -162,14 +162,14 @@ void test_core_env__0(void) (void)p_rmdir(*val); } - git_buf_dispose(&path); - git_buf_dispose(&found); + git_str_dispose(&path); + git_str_dispose(&found); } void test_core_env__1(void) { - git_buf path = GIT_BUF_INIT; + git_str path = GIT_STR_INIT; cl_assert_equal_i( GIT_ENOTFOUND, git_sysdir_find_global_file(&path, "nonexistentfile")); @@ -206,21 +206,21 @@ void test_core_env__1(void) GIT_ENOTFOUND, git_sysdir_find_system_file(&path, "nonexistentfile")); #endif - git_buf_dispose(&path); + git_str_dispose(&path); } static void check_global_searchpath( - const char *path, int position, const char *file, git_buf *temp) + const char *path, int position, const char *file, git_str *temp) { - git_buf out = GIT_BUF_INIT; + git_str out = GIT_STR_INIT; /* build and set new path */ if (position < 0) - cl_git_pass(git_buf_join(temp, GIT_PATH_LIST_SEPARATOR, path, "$PATH")); + cl_git_pass(git_str_join(temp, GIT_PATH_LIST_SEPARATOR, path, "$PATH")); else if (position > 0) - cl_git_pass(git_buf_join(temp, GIT_PATH_LIST_SEPARATOR, "$PATH", path)); + cl_git_pass(git_str_join(temp, GIT_PATH_LIST_SEPARATOR, "$PATH", path)); else - cl_git_pass(git_buf_sets(temp, path)); + cl_git_pass(git_str_sets(temp, path)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, temp->ptr)); @@ -245,12 +245,12 @@ static void check_global_searchpath( cl_assert_equal_i( GIT_ENOTFOUND, git_sysdir_find_global_file(temp, file)); - git_buf_dispose(&out); + git_str_dispose(&out); } void test_core_env__2(void) { - git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT; + git_str path = GIT_STR_INIT, found = GIT_STR_INIT; char testfile[16], tidx = '0'; char **val; const char *testname = "alternate"; @@ -276,9 +276,9 @@ void test_core_env__2(void) * deleting files won't accidentally make a test pass. */ testfile[testlen] = tidx++; - cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile)); + cl_git_pass(git_str_joinpath(&path, path.ptr, testfile)); cl_git_mkfile(path.ptr, "find me"); - git_buf_rtruncate_at_char(&path, '/'); + git_str_rtruncate_at_char(&path, '/'); /* default should be NOTFOUND */ cl_assert_equal_i( @@ -290,32 +290,32 @@ void test_core_env__2(void) check_global_searchpath(path.ptr, 1, testfile, &found); /* cleanup */ - cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile)); + cl_git_pass(git_str_joinpath(&path, path.ptr, testfile)); (void)p_unlink(path.ptr); (void)p_rmdir(*val); } - git_buf_dispose(&path); - git_buf_dispose(&found); + git_str_dispose(&path); + git_str_dispose(&found); } void test_core_env__substitution(void) { - git_buf buf = GIT_BUF_INIT, expected = GIT_BUF_INIT; + git_str buf = GIT_STR_INIT, expected = GIT_STR_INIT; /* Set it to something non-default so we have controllable values */ cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, "/tmp/a")); cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &buf)); cl_assert_equal_s("/tmp/a", buf.ptr); - git_buf_clear(&buf); - cl_git_pass(git_buf_join(&buf, GIT_PATH_LIST_SEPARATOR, "$PATH", "/tmp/b")); + git_str_clear(&buf); + cl_git_pass(git_str_join(&buf, GIT_PATH_LIST_SEPARATOR, "$PATH", "/tmp/b")); cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, buf.ptr)); cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &buf)); - cl_git_pass(git_buf_join(&expected, GIT_PATH_LIST_SEPARATOR, "/tmp/a", "/tmp/b")); + cl_git_pass(git_str_join(&expected, GIT_PATH_LIST_SEPARATOR, "/tmp/a", "/tmp/b")); cl_assert_equal_s(expected.ptr, buf.ptr); - git_buf_dispose(&expected); - git_buf_dispose(&buf); + git_str_dispose(&expected); + git_str_dispose(&buf); } |