From 0e0cf78773bea0d06298ba3bf981a3be839041df Mon Sep 17 00:00:00 2001 From: =?utf8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 2 Oct 2013 14:04:44 +0200 Subject: [PATCH] clone: put the callbacks struct directly in the clone options There's no need for this to be a pointer to somewhere else. --- examples/network/clone.c | 8 +++----- include/git2/clone.h | 4 ++-- include/git2/remote.h | 2 +- src/clone.c | 3 +-- src/remote.c | 4 ++-- tests-clar/clone/empty.c | 2 ++ tests-clar/clone/nonetwork.c | 2 ++ tests-clar/online/clone.c | 34 +++++++++++----------------------- tests-clar/online/fetchhead.c | 2 ++ 9 files changed, 26 insertions(+), 35 deletions(-) diff --git a/examples/network/clone.c b/examples/network/clone.c index f553c4077..db35bd7db 100644 --- a/examples/network/clone.c +++ b/examples/network/clone.c @@ -57,7 +57,6 @@ 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; @@ -75,10 +74,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; - callbacks.transfer_progress = &fetch_progress; - callbacks.credentials = cred_acquire_cb; - callbacks.payload = &pd; - clone_opts.remote_callbacks = &callbacks; + clone_opts.remote_callbacks.transfer_progress = &fetch_progress; + clone_opts.remote_callbacks.credentials = cred_acquire_cb; + clone_opts.remote_callbacks.payload = &pd; // Do the clone error = git_clone(&cloned_repo, url, path, &clone_opts); diff --git a/include/git2/clone.h b/include/git2/clone.h index a341a413c..331cf92e7 100644 --- a/include/git2/clone.h +++ b/include/git2/clone.h @@ -49,7 +49,7 @@ typedef struct git_clone_options { unsigned int version; git_checkout_opts checkout_opts; - git_remote_callbacks *remote_callbacks; + git_remote_callbacks remote_callbacks; int bare; int ignore_cert_errors; @@ -58,7 +58,7 @@ typedef struct git_clone_options { } git_clone_options; #define GIT_CLONE_OPTIONS_VERSION 1 -#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION, {GIT_CHECKOUT_OPTS_VERSION, GIT_CHECKOUT_SAFE_CREATE}} +#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION, {GIT_CHECKOUT_OPTS_VERSION, GIT_CHECKOUT_SAFE_CREATE}, GIT_REMOTE_CALLBACKS_INIT} /** * Clone a remote repository. diff --git a/include/git2/remote.h b/include/git2/remote.h index 8145de180..9858634cc 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -457,7 +457,7 @@ struct git_remote_callbacks { * @param callbacks a pointer to the user's callback settings * @return 0 or an error code */ -GIT_EXTERN(int) git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks); +GIT_EXTERN(int) git_remote_set_callbacks(git_remote *remote, const git_remote_callbacks *callbacks); /** * Get the statistics structure that is filled in by the fetch operation. diff --git a/src/clone.c b/src/clone.c index 1af6e393f..f3e365c07 100644 --- a/src/clone.c +++ b/src/clone.c @@ -315,8 +315,7 @@ static int create_and_configure_origin( if (options->ignore_cert_errors) git_remote_check_cert(origin, 0); - if (options->remote_callbacks && - (error = git_remote_set_callbacks(origin, options->remote_callbacks)) < 0) + if ((error = git_remote_set_callbacks(origin, &options->remote_callbacks)) < 0) goto on_error; if ((error = git_remote_save(origin)) < 0) diff --git a/src/remote.c b/src/remote.c index ace886502..ccedf2386 100644 --- a/src/remote.c +++ b/src/remote.c @@ -1153,7 +1153,7 @@ void git_remote_check_cert(git_remote *remote, int check) remote->check_cert = check; } -int git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks) +int git_remote_set_callbacks(git_remote *remote, const git_remote_callbacks *callbacks) { assert(remote && callbacks); @@ -1162,7 +1162,7 @@ int git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks memcpy(&remote->callbacks, callbacks, sizeof(git_remote_callbacks)); if (remote->transport && remote->transport->set_callbacks) - remote->transport->set_callbacks(remote->transport, + return remote->transport->set_callbacks(remote->transport, remote->callbacks.progress, NULL, remote->callbacks.payload); diff --git a/tests-clar/clone/empty.c b/tests-clar/clone/empty.c index d9dc24fde..6d19244cc 100644 --- a/tests-clar/clone/empty.c +++ b/tests-clar/clone/empty.c @@ -10,12 +10,14 @@ static git_repository *g_repo_cloned; void test_clone_empty__initialize(void) { git_repository *sandbox = cl_git_sandbox_init("empty_bare.git"); + git_remote_callbacks dummy_callbacks = GIT_REMOTE_CALLBACKS_INIT; cl_git_remove_placeholders(git_repository_path(sandbox), "dummy-marker.txt"); g_repo = NULL; memset(&g_options, 0, sizeof(git_clone_options)); g_options.version = GIT_CLONE_OPTIONS_VERSION; + g_options.remote_callbacks = dummy_callbacks; } void test_clone_empty__cleanup(void) diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c index 9b666b3f7..4bcb5be1e 100644 --- a/tests-clar/clone/nonetwork.c +++ b/tests-clar/clone/nonetwork.c @@ -15,6 +15,7 @@ static git_remote* g_remote; void test_clone_nonetwork__initialize(void) { git_checkout_opts dummy_opts = GIT_CHECKOUT_OPTS_INIT; + git_remote_callbacks dummy_callbacks = GIT_REMOTE_CALLBACKS_INIT; g_repo = NULL; @@ -22,6 +23,7 @@ void test_clone_nonetwork__initialize(void) g_options.version = GIT_CLONE_OPTIONS_VERSION; g_options.checkout_opts = dummy_opts; g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE; + g_options.remote_callbacks = dummy_callbacks; } void test_clone_nonetwork__cleanup(void) diff --git a/tests-clar/online/clone.c b/tests-clar/online/clone.c index 9a64ba166..4a6ade52d 100644 --- a/tests-clar/online/clone.c +++ b/tests-clar/online/clone.c @@ -18,6 +18,7 @@ static git_clone_options g_options; void test_online_clone__initialize(void) { git_checkout_opts dummy_opts = GIT_CHECKOUT_OPTS_INIT; + git_remote_callbacks dummy_callbacks = GIT_REMOTE_CALLBACKS_INIT; g_repo = NULL; @@ -25,6 +26,7 @@ void test_online_clone__initialize(void) g_options.version = GIT_CLONE_OPTIONS_VERSION; g_options.checkout_opts = dummy_opts; g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE; + g_options.remote_callbacks = dummy_callbacks; } void test_online_clone__cleanup(void) @@ -100,15 +102,11 @@ 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; - - callbacks.transfer_progress = &fetch_progress; - callbacks.payload = &fetch_progress_cb_was_called; - g_options.remote_callbacks = &callbacks; + g_options.remote_callbacks.transfer_progress = &fetch_progress; + g_options.remote_callbacks.payload = &fetch_progress_cb_was_called; cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options)); @@ -175,12 +173,10 @@ static int update_tips(const char *refname, const git_oid *a, const git_oid *b, void test_online_clone__custom_remote_callbacks(void) { - git_remote_callbacks remote_callbacks = GIT_REMOTE_CALLBACKS_INIT; int callcount = 0; - g_options.remote_callbacks = &remote_callbacks; - remote_callbacks.update_tips = update_tips; - remote_callbacks.payload = &callcount; + g_options.remote_callbacks.update_tips = update_tips; + g_options.remote_callbacks.payload = &callcount; cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options)); cl_assert(callcount > 0); @@ -194,13 +190,11 @@ void test_online_clone__credentials(void) cl_getenv("GITTEST_REMOTE_USER"), cl_getenv("GITTEST_REMOTE_PASS") }; - git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; if (!remote_url) return; - callbacks.credentials = git_cred_userpass; - callbacks.payload = &user_pass; - g_options.remote_callbacks = &callbacks; + g_options.remote_callbacks.credentials = git_cred_userpass; + g_options.remote_callbacks.payload = &user_pass; cl_git_pass(git_clone(&g_repo, remote_url, "./foo", &g_options)); git_repository_free(g_repo); g_repo = NULL; @@ -213,11 +207,8 @@ void test_online_clone__bitbucket_style(void) "libgit2", "libgit2" }; - git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; - - callbacks.credentials = git_cred_userpass; - callbacks.payload = &user_pass; - g_options.remote_callbacks = &callbacks; + g_options.remote_callbacks.credentials = git_cred_userpass; + g_options.remote_callbacks.payload = &user_pass; cl_git_pass(git_clone(&g_repo, BB_REPO_URL, "./foo", &g_options)); git_repository_free(g_repo); g_repo = NULL; @@ -247,10 +238,7 @@ static int cancel_at_half(const git_transfer_progress *stats, void *payload) void test_online_clone__can_cancel(void) { - git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; - - callbacks.transfer_progress = cancel_at_half; - g_options.remote_callbacks = &callbacks; + g_options.remote_callbacks.transfer_progress = cancel_at_half; cl_git_fail_with(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options), GIT_EUSER); } diff --git a/tests-clar/online/fetchhead.c b/tests-clar/online/fetchhead.c index 5d9eb1318..57b183f88 100644 --- a/tests-clar/online/fetchhead.c +++ b/tests-clar/online/fetchhead.c @@ -12,10 +12,12 @@ static git_clone_options g_options; void test_online_fetchhead__initialize(void) { + git_remote_callbacks dummy_callbacks = GIT_REMOTE_CALLBACKS_INIT; g_repo = NULL; memset(&g_options, 0, sizeof(git_clone_options)); g_options.version = GIT_CLONE_OPTIONS_VERSION; + g_options.remote_callbacks = dummy_callbacks; } void test_online_fetchhead__cleanup(void) -- 2.39.5