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/remote/remotes.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/network/remote/remotes.c')
-rw-r--r-- | tests/network/remote/remotes.c | 41 |
1 files changed, 21 insertions, 20 deletions
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) |