]> git.proxmox.com Git - libgit2.git/blobdiff - tests/online/fetch.c
New upstream version 1.1.0+dfsg.1
[libgit2.git] / tests / online / fetch.c
index ec16dd2fdfa64f575d75cb682ba0f4e3c7dc77bf..f939a16b8b69be6f67ad58cb84c1630b817f9186 100644 (file)
@@ -25,7 +25,7 @@ static int update_tips(const char *refname, const git_oid *a, const git_oid *b,
        return 0;
 }
 
-static int progress(const git_transfer_progress *stats, void *payload)
+static int progress(const git_indexer_progress *stats, void *payload)
 {
        size_t *bytes_received = (size_t *)payload;
        *bytes_received = stats->received_bytes;
@@ -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;
+       options.download_tags = flag;
        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, 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);
 
@@ -58,17 +54,17 @@ static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n)
 
 void test_online_fetch__default_git(void)
 {
-       do_fetch("git://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 5);
+       do_fetch("git://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 6);
 }
 
 void test_online_fetch__default_http(void)
 {
-       do_fetch("http://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 5);
+       do_fetch("http://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 6);
 }
 
 void test_online_fetch__default_https(void)
 {
-       do_fetch("https://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 5);
+       do_fetch("https://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 6);
 }
 
 void test_online_fetch__no_tags_git(void)
@@ -85,18 +81,18 @@ 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, NULL, 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, NULL, NULL);
+       cl_git_pass(git_remote_download(remote, NULL, NULL));
        git_remote_disconnect(remote);
-       
+
        git_remote_free(remote);
 }
 
-static int transferProgressCallback(const git_transfer_progress *stats, void *payload)
+static int transferProgressCallback(const git_indexer_progress *stats, void *payload)
 {
        bool *invoked = (bool *)payload;
 
@@ -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,25 +117,24 @@ 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, NULL, 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, NULL));
+       cl_git_pass(git_remote_update_tips(remote, &options.callbacks, 1, options.download_tags, NULL));
        git_remote_disconnect(remote);
 
        git_remote_free(remote);
        git_repository_free(_repository);
 }
 
-static int cancel_at_half(const git_transfer_progress *stats, void *payload)
+static int cancel_at_half(const git_indexer_progress *stats, void *payload)
 {
        GIT_UNUSED(payload);
 
@@ -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, NULL, 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, NULL, 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, NULL, NULL));
        git_remote_disconnect(remote);
        cl_git_pass(git_remote_ls(&refs, &refs_len, remote));
 
@@ -202,3 +196,14 @@ void test_online_fetch__remote_symrefs(void)
 
        git_remote_free(remote);
 }
+
+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, NULL));
+       cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
+
+       git_remote_free(remote);
+}