diff options
| author | Carlos Martín Nieto <cmn@dwim.me> | 2015-04-21 22:10:36 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-05-13 09:46:35 +0200 |
| commit | 8f0104ecc54db00a075310ab744a19eb60e3d740 (patch) | |
| tree | 775b3237a853c556a4d44840fc6c562e7b114415 /tests/online/fetch.c | |
| parent | 05259114427234831cf4915cbe40a5bb8ea021b0 (diff) | |
| download | libgit2-8f0104ecc54db00a075310ab744a19eb60e3d740.tar.gz | |
Remove the callbacks struct from the remote
Having the setting be different from calling its actions was not a great
idea and made for the sake of the wrong convenience.
Instead of that, accept either fetch options, push options or the
callbacks when dealing with the remote. The fetch options are currently
only the callbacks, but more options will be moved from setters and
getters on the remote to the options.
This does mean passing the same struct along the different functions but
the typical use-case will only call git_remote_fetch() or
git_remote_push() and so won't notice much difference.
Diffstat (limited to 'tests/online/fetch.c')
| -rw-r--r-- | tests/online/fetch.c | 54 |
1 files changed, 24 insertions, 30 deletions
diff --git a/tests/online/fetch.c b/tests/online/fetch.c index 22f32ba1a..1a0f05039 100644 --- a/tests/online/fetch.c +++ b/tests/online/fetch.c @@ -35,21 +35,17 @@ static int progress(const git_transfer_progress *stats, void *payload) static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n) { git_remote *remote; - git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; + git_fetch_options options = GIT_FETCH_OPTIONS_INIT; size_t bytes_received = 0; - callbacks.transfer_progress = progress; - callbacks.update_tips = update_tips; - callbacks.payload = &bytes_received; + options.callbacks.transfer_progress = progress; + options.callbacks.update_tips = update_tips; + options.callbacks.payload = &bytes_received; counter = 0; cl_git_pass(git_remote_create(&remote, _repo, "test", url)); - git_remote_set_callbacks(remote, &callbacks); git_remote_set_autotag(remote, flag); - cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); - cl_git_pass(git_remote_download(remote, NULL)); - cl_git_pass(git_remote_update_tips(remote, NULL)); - git_remote_disconnect(remote); + cl_git_pass(git_remote_fetch(remote, NULL, &options, NULL)); cl_assert_equal_i(counter, n); cl_assert(bytes_received > 0); @@ -85,12 +81,12 @@ void test_online_fetch__fetch_twice(void) { git_remote *remote; cl_git_pass(git_remote_create(&remote, _repo, "test", "git://github.com/libgit2/TestGitRepository.git")); - cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); - cl_git_pass(git_remote_download(remote, NULL)); + cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL)); + cl_git_pass(git_remote_download(remote, NULL, NULL)); git_remote_disconnect(remote); - git_remote_connect(remote, GIT_DIRECTION_FETCH); - cl_git_pass(git_remote_download(remote, NULL)); + git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL); + cl_git_pass(git_remote_download(remote, NULL, NULL)); git_remote_disconnect(remote); git_remote_free(remote); @@ -110,7 +106,7 @@ void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date git_repository *_repository; bool invoked = false; git_remote *remote; - git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; + git_fetch_options options = GIT_FETCH_OPTIONS_INIT; git_clone_options opts = GIT_CLONE_OPTIONS_INIT; opts.bare = true; @@ -121,18 +117,17 @@ void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date cl_git_pass(git_repository_open(&_repository, "./fetch/lg2")); cl_git_pass(git_remote_lookup(&remote, _repository, "origin")); - cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); + cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL)); cl_assert_equal_i(false, invoked); - callbacks.transfer_progress = &transferProgressCallback; - callbacks.payload = &invoked; - git_remote_set_callbacks(remote, &callbacks); - cl_git_pass(git_remote_download(remote, NULL)); + options.callbacks.transfer_progress = &transferProgressCallback; + options.callbacks.payload = &invoked; + cl_git_pass(git_remote_download(remote, NULL, &options)); cl_assert_equal_i(false, invoked); - cl_git_pass(git_remote_update_tips(remote, NULL)); + cl_git_pass(git_remote_update_tips(remote, &options.callbacks, NULL)); git_remote_disconnect(remote); git_remote_free(remote); @@ -152,17 +147,16 @@ void test_online_fetch__can_cancel(void) { git_remote *remote; size_t bytes_received = 0; - git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; + git_fetch_options options = GIT_FETCH_OPTIONS_INIT; cl_git_pass(git_remote_create(&remote, _repo, "test", "http://github.com/libgit2/TestGitRepository.git")); - callbacks.transfer_progress = cancel_at_half; - callbacks.payload = &bytes_received; - git_remote_set_callbacks(remote, &callbacks); + options.callbacks.transfer_progress = cancel_at_half; + options.callbacks.payload = &bytes_received; - cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); - cl_git_fail_with(git_remote_download(remote, NULL), -4321); + cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL)); + cl_git_fail_with(git_remote_download(remote, NULL, &options), -4321); git_remote_disconnect(remote); git_remote_free(remote); } @@ -175,7 +169,7 @@ void test_online_fetch__ls_disconnected(void) cl_git_pass(git_remote_create(&remote, _repo, "test", "http://github.com/libgit2/TestGitRepository.git")); - cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); + cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL)); cl_git_pass(git_remote_ls(&refs, &refs_len_before, remote)); git_remote_disconnect(remote); cl_git_pass(git_remote_ls(&refs, &refs_len_after, remote)); @@ -193,7 +187,7 @@ void test_online_fetch__remote_symrefs(void) cl_git_pass(git_remote_create(&remote, _repo, "test", "http://github.com/libgit2/TestGitRepository.git")); - cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); + cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL)); git_remote_disconnect(remote); cl_git_pass(git_remote_ls(&refs, &refs_len, remote)); @@ -208,8 +202,8 @@ void test_online_fetch__twice(void) git_remote *remote; cl_git_pass(git_remote_create(&remote, _repo, "test", "http://github.com/libgit2/TestGitRepository.git")); - cl_git_pass(git_remote_fetch(remote, NULL, NULL)); - cl_git_pass(git_remote_fetch(remote, NULL, NULL)); + cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL)); + cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL)); git_remote_free(remote); } |
