summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2013-09-16 04:20:05 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2013-10-02 06:41:42 +0200
commitd31402a3fc4aa1b7d48ba43fd3bb072e7d69a527 (patch)
treecc8eb1e1801c98c25349951d6cd3667d94d9ea19
parent71e33d2649f990086237a6cd0fdb7f7d6f742b51 (diff)
downloadlibgit2-d31402a3fc4aa1b7d48ba43fd3bb072e7d69a527.tar.gz
remote: put the _download() callback with the others
The text progress and update_tips callbacks are already part of the struct, which was meant to unify the callback setup, but the download one was left out.
-rw-r--r--examples/network/clone.c6
-rw-r--r--examples/network/fetch.c2
-rw-r--r--include/git2/clone.h2
-rw-r--r--include/git2/remote.h11
-rw-r--r--src/clone.c3
-rw-r--r--src/fetch.c8
-rw-r--r--src/fetch.h5
-rw-r--r--src/remote.c7
-rw-r--r--tests-clar/network/fetchlocal.c14
-rw-r--r--tests-clar/network/remote/local.c10
-rw-r--r--tests-clar/online/clone.c20
-rw-r--r--tests-clar/online/fetch.c18
-rw-r--r--tests-clar/online/fetchhead.c2
-rw-r--r--tests-clar/online/push.c2
-rw-r--r--tests-clar/online/push_util.h2
15 files changed, 66 insertions, 46 deletions
diff --git a/examples/network/clone.c b/examples/network/clone.c
index a09a94728..f1002656c 100644
--- a/examples/network/clone.c
+++ b/examples/network/clone.c
@@ -57,6 +57,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
git_repository *cloned_repo = NULL;
git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
git_checkout_opts checkout_opts = GIT_CHECKOUT_OPTS_INIT;
+ git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
const char *url = argv[1];
const char *path = argv[2];
int error;
@@ -74,8 +75,9 @@ int do_clone(git_repository *repo, int argc, char **argv)
checkout_opts.progress_cb = checkout_progress;
checkout_opts.progress_payload = &pd;
clone_opts.checkout_opts = checkout_opts;
- clone_opts.fetch_progress_cb = &fetch_progress;
- clone_opts.fetch_progress_payload = &pd;
+ callbacks.transfer_progress = &fetch_progress;
+ callbacks.payload = &pd;
+ clone_opts.remote_callbacks = &callbacks;
clone_opts.cred_acquire_cb = cred_acquire_cb;
// Do the clone
diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index ce016ce0b..1de223373 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -35,7 +35,7 @@ static void *download(void *ptr)
// Download the packfile and index it. This function updates the
// amount of received data and the indexer stats which lets you
// inform the user about progress.
- if (git_remote_download(data->remote, NULL, NULL) < 0) {
+ if (git_remote_download(data->remote) < 0) {
data->ret = -1;
goto exit;
}
diff --git a/include/git2/clone.h b/include/git2/clone.h
index 580352ac1..122806ad5 100644
--- a/include/git2/clone.h
+++ b/include/git2/clone.h
@@ -69,8 +69,6 @@ typedef struct git_clone_options {
git_checkout_opts checkout_opts;
git_repository_init_options *init_options;
int bare;
- git_transfer_progress_callback fetch_progress_cb;
- void *fetch_progress_payload;
const char *remote_name;
const char *pushurl;
diff --git a/include/git2/remote.h b/include/git2/remote.h
index fa8b378c6..2bde5e365 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -257,17 +257,9 @@ GIT_EXTERN(int) git_remote_ls(git_remote *remote, git_headlist_cb list_cb, void
* The .idx file will be created and both it and the packfile with be
* renamed to their final name.
*
- * @param remote the remote to download from
- * @param progress_cb function to call with progress information. Be aware that
- * this is called inline with network and indexing operations, so performance
- * may be affected.
- * @param payload payload for the progress callback
* @return 0 or an error code
*/
-GIT_EXTERN(int) git_remote_download(
- git_remote *remote,
- git_transfer_progress_callback progress_cb,
- void *payload);
+GIT_EXTERN(int) git_remote_download(git_remote *remote);
/**
* Check whether the remote is connected
@@ -403,6 +395,7 @@ struct git_remote_callbacks {
unsigned int version;
void (*progress)(const char *str, int len, void *data);
int (*completion)(git_remote_completion_type type, void *data);
+ int (*transfer_progress)(const git_transfer_progress *stats, void *data);
int (*update_tips)(const char *refname, const git_oid *a, const git_oid *b, void *data);
void *payload;
};
diff --git a/src/clone.c b/src/clone.c
index ff251be1b..90d677bbb 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -380,8 +380,7 @@ static int setup_remotes_and_fetch(
if ((retcode = git_remote_connect(origin, GIT_DIRECTION_FETCH)) < 0)
goto on_error;
- if ((retcode = git_remote_download(origin, options->fetch_progress_cb,
- options->fetch_progress_payload)) < 0)
+ if ((retcode = git_remote_download(origin)) < 0)
goto on_error;
/* Create "origin/foo" branches for all remote branches */
diff --git a/src/fetch.c b/src/fetch.c
index 03fad5fec..5d97913e8 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -119,15 +119,13 @@ int git_fetch_negotiate(git_remote *remote)
remote->refs.length);
}
-int git_fetch_download_pack(
- git_remote *remote,
- git_transfer_progress_callback progress_cb,
- void *progress_payload)
+int git_fetch_download_pack(git_remote *remote)
{
git_transport *t = remote->transport;
if(!remote->need_pack)
return 0;
- return t->download_pack(t, remote->repo, &remote->stats, progress_cb, progress_payload);
+ return t->download_pack(t, remote->repo, &remote->stats,
+ remote->callbacks.transfer_progress, remote->callbacks.payload);
}
diff --git a/src/fetch.h b/src/fetch.h
index 059251d04..9605da1b5 100644
--- a/src/fetch.h
+++ b/src/fetch.h
@@ -11,10 +11,7 @@
int git_fetch_negotiate(git_remote *remote);
-int git_fetch_download_pack(
- git_remote *remote,
- git_transfer_progress_callback progress_cb,
- void *progress_payload);
+int git_fetch_download_pack(git_remote *remote);
int git_fetch__download_pack(
git_transport *t,
diff --git a/src/remote.c b/src/remote.c
index 95b907ff1..e4696c4ec 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -742,10 +742,7 @@ static int remote_head_cmp(const void *_a, const void *_b)
return git__strcmp_cb(a->name, b->name);
}
-int git_remote_download(
- git_remote *remote,
- git_transfer_progress_callback progress_cb,
- void *progress_payload)
+int git_remote_download(git_remote *remote)
{
int error;
git_vector refs;
@@ -767,7 +764,7 @@ int git_remote_download(
if ((error = git_fetch_negotiate(remote)) < 0)
return error;
- return git_fetch_download_pack(remote, progress_cb, progress_payload);
+ return git_fetch_download_pack(remote);
}
static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *update_heads, const char *fetchspec_src)
diff --git a/tests-clar/network/fetchlocal.c b/tests-clar/network/fetchlocal.c
index 09335b3df..28c7115bf 100644
--- a/tests-clar/network/fetchlocal.c
+++ b/tests-clar/network/fetchlocal.c
@@ -25,13 +25,18 @@ void test_network_fetchlocal__complete(void)
git_strarray refnames = {0};
const char *url = cl_git_fixture_url("testrepo.git");
+ git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+
+ callbacks.transfer_progress = transfer_cb;
+ callbacks.payload = &callcount;
cl_set_cleanup(&cleanup_local_repo, "foo");
cl_git_pass(git_repository_init(&repo, "foo", true));
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
+ git_remote_set_callbacks(origin, &callbacks);
cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(origin, transfer_cb, &callcount));
+ cl_git_pass(git_remote_download(origin));
cl_git_pass(git_remote_update_tips(origin));
cl_git_pass(git_reference_list(&refnames, repo));
@@ -56,6 +61,10 @@ void test_network_fetchlocal__partial(void)
int callcount = 0;
git_strarray refnames = {0};
const char *url;
+ git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+
+ callbacks.transfer_progress = transfer_cb;
+ callbacks.payload = &callcount;
cl_set_cleanup(&cleanup_sandbox, NULL);
cl_git_pass(git_reference_list(&refnames, repo));
@@ -63,8 +72,9 @@ void test_network_fetchlocal__partial(void)
url = cl_git_fixture_url("testrepo.git");
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
+ git_remote_set_callbacks(origin, &callbacks);
cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(origin, transfer_cb, &callcount));
+ cl_git_pass(git_remote_download(origin));
cl_git_pass(git_remote_update_tips(origin));
git_strarray_free(&refnames);
diff --git a/tests-clar/network/remote/local.c b/tests-clar/network/remote/local.c
index c8edd37f5..6d658a2e4 100644
--- a/tests-clar/network/remote/local.c
+++ b/tests-clar/network/remote/local.c
@@ -123,7 +123,7 @@ void test_network_remote_local__shorthand_fetch_refspec0(void)
cl_git_pass(git_remote_add_fetch(remote, refspec));
cl_git_pass(git_remote_add_fetch(remote, refspec2));
- cl_git_pass(git_remote_download(remote, NULL, NULL));
+ cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote));
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/sloppy/master"));
@@ -145,7 +145,7 @@ void test_network_remote_local__shorthand_fetch_refspec1(void)
cl_git_pass(git_remote_add_fetch(remote, refspec));
cl_git_pass(git_remote_add_fetch(remote, refspec2));
- cl_git_pass(git_remote_download(remote, NULL, NULL));
+ cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote));
cl_git_fail(git_reference_lookup(&ref, repo, "refs/remotes/master"));
@@ -160,7 +160,7 @@ void test_network_remote_local__tagopt(void)
connect_to_local_repository(cl_fixture("testrepo.git"));
git_remote_set_autotag(remote, GIT_REMOTE_DOWNLOAD_TAGS_ALL);
- cl_git_pass(git_remote_download(remote, NULL, NULL));
+ cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote));
@@ -179,7 +179,7 @@ void test_network_remote_local__push_to_bare_remote(void)
/* Get some commits */
connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_add_fetch(remote, "master:master"));
- cl_git_pass(git_remote_download(remote, NULL, NULL));
+ cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote));
git_remote_disconnect(remote);
@@ -215,7 +215,7 @@ void test_network_remote_local__push_to_non_bare_remote(void)
/* Get some commits */
connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_add_fetch(remote, "master:master"));
- cl_git_pass(git_remote_download(remote, NULL, NULL));
+ cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote));
git_remote_disconnect(remote);
diff --git a/tests-clar/online/clone.c b/tests-clar/online/clone.c
index dc5aa4150..bda260858 100644
--- a/tests-clar/online/clone.c
+++ b/tests-clar/online/clone.c
@@ -100,11 +100,15 @@ void test_online_clone__can_checkout_a_cloned_repo(void)
bool checkout_progress_cb_was_called = false,
fetch_progress_cb_was_called = false;
+ git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+
g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
g_options.checkout_opts.progress_cb = &checkout_progress;
g_options.checkout_opts.progress_payload = &checkout_progress_cb_was_called;
- g_options.fetch_progress_cb = &fetch_progress;
- g_options.fetch_progress_payload = &fetch_progress_cb_was_called;
+
+ callbacks.transfer_progress = &fetch_progress;
+ callbacks.payload = &fetch_progress_cb_was_called;
+ g_options.remote_callbacks = &callbacks;
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
@@ -199,6 +203,16 @@ static int cancel_at_half(const git_transfer_progress *stats, void *payload)
void test_online_clone__can_cancel(void)
{
- g_options.fetch_progress_cb = cancel_at_half;
+ git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+
+ callbacks.transfer_progress = cancel_at_half;
+ g_options.remote_callbacks = &callbacks;
+
cl_git_fail_with(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options), GIT_EUSER);
}
+
+
+
+
+
+
diff --git a/tests-clar/online/fetch.c b/tests-clar/online/fetch.c
index f76c6cff9..df1b2e288 100644
--- a/tests-clar/online/fetch.c
+++ b/tests-clar/online/fetch.c
@@ -38,14 +38,16 @@ static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n)
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
size_t bytes_received = 0;
+ callbacks.transfer_progress = progress;
callbacks.update_tips = update_tips;
+ 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, progress, &bytes_received));
+ cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote));
git_remote_disconnect(remote);
cl_assert_equal_i(counter, n);
@@ -93,6 +95,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_clone_options opts = GIT_CLONE_OPTIONS_INIT;
opts.bare = true;
@@ -107,7 +110,10 @@ void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date
cl_assert_equal_i(false, invoked);
- cl_git_pass(git_remote_download(remote, &transferProgressCallback, &invoked));
+ callbacks.transfer_progress = &transferProgressCallback;
+ callbacks.payload = &invoked;
+ git_remote_set_callbacks(remote, &callbacks);
+ cl_git_pass(git_remote_download(remote));
cl_assert_equal_i(false, invoked);
@@ -131,11 +137,17 @@ void test_online_fetch__can_cancel(void)
{
git_remote *remote;
size_t bytes_received = 0;
+ git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_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);
+
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
- cl_git_fail_with(git_remote_download(remote, cancel_at_half, &bytes_received), GIT_EUSER);
+ cl_git_fail_with(git_remote_download(remote), GIT_EUSER);
git_remote_disconnect(remote);
git_remote_free(remote);
}
diff --git a/tests-clar/online/fetchhead.c b/tests-clar/online/fetchhead.c
index 58717eef8..5d9eb1318 100644
--- a/tests-clar/online/fetchhead.c
+++ b/tests-clar/online/fetchhead.c
@@ -48,7 +48,7 @@ static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fet
}
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(remote, NULL, NULL));
+ cl_git_pass(git_remote_download(remote));
cl_git_pass(git_remote_update_tips(remote));
git_remote_disconnect(remote);
git_remote_free(remote);
diff --git a/tests-clar/online/push.c b/tests-clar/online/push.c
index 6a4a9b281..d0d4ed05b 100644
--- a/tests-clar/online/push.c
+++ b/tests-clar/online/push.c
@@ -326,7 +326,7 @@ void test_online_push__initialize(void)
/* Now that we've deleted everything, fetch from the remote */
cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(_remote, NULL, NULL));
+ cl_git_pass(git_remote_download(_remote));
cl_git_pass(git_remote_update_tips(_remote));
git_remote_disconnect(_remote);
} else
diff --git a/tests-clar/online/push_util.h b/tests-clar/online/push_util.h
index 759122aa6..659c6dd54 100644
--- a/tests-clar/online/push_util.h
+++ b/tests-clar/online/push_util.h
@@ -12,7 +12,7 @@ extern const git_oid OID_ZERO;
* @param data pointer to a record_callbacks_data instance
*/
#define RECORD_CALLBACKS_INIT(data) \
- { GIT_REMOTE_CALLBACKS_VERSION, NULL, NULL, record_update_tips_cb, data }
+ { GIT_REMOTE_CALLBACKS_VERSION, NULL, NULL, NULL, record_update_tips_cb, data }
typedef struct {
char *name;