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/network | |
| 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/network')
| -rw-r--r-- | tests/network/fetchlocal.c | 1 | ||||
| -rw-r--r-- | tests/network/remote/defaultbranch.c | 1 | ||||
| -rw-r--r-- | tests/network/remote/local.c | 17 | ||||
| -rw-r--r-- | tests/network/remote/remotes.c | 41 |
4 files changed, 29 insertions, 31 deletions
diff --git a/tests/network/fetchlocal.c b/tests/network/fetchlocal.c index 13f03100b..302d1544c 100644 --- a/tests/network/fetchlocal.c +++ b/tests/network/fetchlocal.c @@ -1,6 +1,5 @@ #include "clar_libgit2.h" -#include "buffer.h" #include "path.h" #include "remote.h" diff --git a/tests/network/remote/defaultbranch.c b/tests/network/remote/defaultbranch.c index b0417f764..a7c0d81f6 100644 --- a/tests/network/remote/defaultbranch.c +++ b/tests/network/remote/defaultbranch.c @@ -1,5 +1,4 @@ #include "clar_libgit2.h" -#include "buffer.h" #include "refspec.h" #include "remote.h" diff --git a/tests/network/remote/local.c b/tests/network/remote/local.c index 16cce6777..f174044d7 100644 --- a/tests/network/remote/local.c +++ b/tests/network/remote/local.c @@ -1,11 +1,10 @@ #include "clar_libgit2.h" -#include "buffer.h" #include "path.h" #include "posix.h" #include "git2/sys/repository.h" static git_repository *repo; -static git_buf file_path_buf = GIT_BUF_INIT; +static git_str file_path_buf = GIT_STR_INIT; static git_remote *remote; static char *push_refspec_strings[] = { @@ -25,7 +24,7 @@ void test_network_remote_local__initialize(void) void test_network_remote_local__cleanup(void) { - git_buf_dispose(&file_path_buf); + git_str_dispose(&file_path_buf); git_remote_free(remote); remote = NULL; @@ -38,9 +37,9 @@ void test_network_remote_local__cleanup(void) static void connect_to_local_repository(const char *local_repository) { - git_buf_sets(&file_path_buf, cl_git_path_url(local_repository)); + git_str_sets(&file_path_buf, cl_git_path_url(local_repository)); - cl_git_pass(git_remote_create_anonymous(&remote, repo, git_buf_cstr(&file_path_buf))); + cl_git_pass(git_remote_create_anonymous(&remote, repo, git_str_cstr(&file_path_buf))); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL)); } @@ -70,9 +69,9 @@ void test_network_remote_local__retrieve_advertised_before_connect(void) const git_remote_head **refs; size_t refs_len = 0; - git_buf_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git"))); + git_str_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git"))); - cl_git_pass(git_remote_create_anonymous(&remote, repo, git_buf_cstr(&file_path_buf))); + cl_git_pass(git_remote_create_anonymous(&remote, repo, git_str_cstr(&file_path_buf))); cl_git_fail(git_remote_ls(&refs, &refs_len, remote)); } @@ -472,10 +471,10 @@ void test_network_remote_local__anonymous_remote_inmemory_repo(void) git_repository *inmemory; git_remote *remote; - git_buf_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git"))); + git_str_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git"))); cl_git_pass(git_repository_new(&inmemory)); - cl_git_pass(git_remote_create_anonymous(&remote, inmemory, git_buf_cstr(&file_path_buf))); + cl_git_pass(git_remote_create_anonymous(&remote, inmemory, git_str_cstr(&file_path_buf))); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL)); cl_assert(git_remote_connected(remote)); git_remote_disconnect(remote); diff --git a/tests/network/remote/remotes.c b/tests/network/remote/remotes.c index ed6a89075..79c4f39fa 100644 --- a/tests/network/remote/remotes.c +++ b/tests/network/remote/remotes.c @@ -1,6 +1,5 @@ #include "clar_libgit2.h" #include "config/config_helpers.h" -#include "buffer.h" #include "refspec.h" #include "remote.h" @@ -28,7 +27,7 @@ void test_network_remote_remotes__cleanup(void) void test_network_remote_remotes__parsing(void) { - git_buf url = GIT_BUF_INIT; + git_str url = GIT_STR_INIT; git_remote *_remote2 = NULL; cl_assert_equal_s(git_remote_name(_remote), "test"); @@ -53,7 +52,7 @@ void test_network_remote_remotes__parsing(void) cl_assert_equal_s(url.ptr, "git://github.com/libgit2/pushlibgit2"); git_remote_free(_remote2); - git_buf_dispose(&url); + git_str_dispose(&url); } static int remote_ready_callback(git_remote *remote, int direction, void *payload) @@ -79,7 +78,7 @@ static int remote_ready_callback(git_remote *remote, int direction, void *payloa void test_network_remote_remotes__remote_ready(void) { - git_buf url = GIT_BUF_INIT; + git_str url = GIT_STR_INIT; git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; callbacks.remote_ready = remote_ready_callback; @@ -95,29 +94,31 @@ void test_network_remote_remotes__remote_ready(void) cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks)); cl_assert_equal_s(url.ptr, "push_url"); - git_buf_dispose(&url); + git_str_dispose(&url); } #ifndef GIT_DEPRECATE_HARD static int urlresolve_callback(git_buf *url_resolved, const char *url, int direction, void *payload) { + int error = -1; + cl_assert(strcmp(url, "git://github.com/libgit2/libgit2") == 0); cl_assert(strcmp(payload, "payload") == 0); cl_assert(url_resolved->size == 0); if (direction == GIT_DIRECTION_PUSH) - git_buf_sets(url_resolved, "pushresolve"); + error = git_buf_set(url_resolved, "pushresolve", strlen("pushresolve") + 1); if (direction == GIT_DIRECTION_FETCH) - git_buf_sets(url_resolved, "fetchresolve"); + error = git_buf_set(url_resolved, "fetchresolve", strlen("fetchresolve") + 1); - return GIT_OK; + return error; } #endif void test_network_remote_remotes__urlresolve(void) { #ifndef GIT_DEPRECATE_HARD - git_buf url = GIT_BUF_INIT; + git_str url = GIT_STR_INIT; git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; callbacks.resolve_url = urlresolve_callback; @@ -133,7 +134,7 @@ void test_network_remote_remotes__urlresolve(void) cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks)); cl_assert_equal_s(url.ptr, "pushresolve"); - git_buf_dispose(&url); + git_str_dispose(&url); #endif } @@ -151,7 +152,7 @@ static int urlresolve_passthrough_callback(git_buf *url_resolved, const char *ur void test_network_remote_remotes__urlresolve_passthrough(void) { #ifndef GIT_DEPRECATE_HARD - git_buf url = GIT_BUF_INIT; + git_str url = GIT_STR_INIT; const char *orig_url = "git://github.com/libgit2/libgit2"; git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; @@ -167,13 +168,13 @@ void test_network_remote_remotes__urlresolve_passthrough(void) cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks)); cl_assert_equal_s(url.ptr, orig_url); - git_buf_dispose(&url); + git_str_dispose(&url); #endif } void test_network_remote_remotes__instance_url(void) { - git_buf url = GIT_BUF_INIT; + git_str url = GIT_STR_INIT; const char *orig_url = "git://github.com/libgit2/libgit2"; cl_assert_equal_s(git_remote_name(_remote), "test"); @@ -181,11 +182,11 @@ void test_network_remote_remotes__instance_url(void) cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL)); cl_assert_equal_s(url.ptr, orig_url); - git_buf_clear(&url); + git_str_clear(&url); cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL)); cl_assert_equal_s(url.ptr, orig_url); - git_buf_clear(&url); + git_str_clear(&url); /* Setting the instance url updates the fetch and push URLs */ git_remote_set_instance_url(_remote, "https://github.com/new/remote/url"); @@ -194,11 +195,11 @@ void test_network_remote_remotes__instance_url(void) cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL)); cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url"); - git_buf_clear(&url); + git_str_clear(&url); cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL)); cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url"); - git_buf_clear(&url); + git_str_clear(&url); /* Setting the instance push url updates only the push URL */ git_remote_set_instance_pushurl(_remote, "https://github.com/new/push/url"); @@ -207,13 +208,13 @@ void test_network_remote_remotes__instance_url(void) cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL)); cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url"); - git_buf_clear(&url); + git_str_clear(&url); cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL)); cl_assert_equal_s(url.ptr, "https://github.com/new/push/url"); - git_buf_clear(&url); + git_str_clear(&url); - git_buf_dispose(&url); + git_str_dispose(&url); } void test_network_remote_remotes__pushurl(void) |
