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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
diff --git a/examples/network/clone.c b/examples/network/clone.c
index a09a947..f100265 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 ce016ce..1de2233 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 580352a..122806a 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 fa8b378..2bde5e3 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 ff251be..90d677b 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 03fad5f..5d97913 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 059251d..9605da1 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 95b907f..e4696c4 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 09335b3..28c7115 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 c8edd37..6d658a2 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 dc5aa41..bda2608 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 f76c6cf..df1b2e2 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 58717ee..5d9eb13 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 6a4a9b2..d0d4ed0 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 759122a..659c6dd 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;