diff options
-rw-r--r-- | include/git2/remote.h | 6 | ||||
-rw-r--r-- | include/git2/sys/transport.h | 20 | ||||
-rw-r--r-- | include/git2/transport.h | 3 | ||||
-rw-r--r-- | include/git2/types.h | 6 | ||||
-rw-r--r-- | src/remote.c | 27 | ||||
-rw-r--r-- | src/remote.h | 2 | ||||
-rw-r--r-- | tests/clone/transport.c | 8 | ||||
-rw-r--r-- | tests/network/remote/remotes.c | 6 | ||||
-rw-r--r-- | tests/online/clone.c | 8 | ||||
-rw-r--r-- | tests/online/push_util.h | 2 |
10 files changed, 32 insertions, 56 deletions
diff --git a/include/git2/remote.h b/include/git2/remote.h index 41cf8512f..22aad5ad4 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -484,6 +484,12 @@ struct git_remote_callbacks { git_push_negotiation push_negotiation; /** + * Create the transport to use for this operation. Leave NULL + * to auto-detect. + */ + git_transport_cb transport; + + /** * This will be passed to each of the callbacks in this struct * as the last parameter. */ diff --git a/include/git2/sys/transport.h b/include/git2/sys/transport.h index d6ca8ff05..867fbcbce 100644 --- a/include/git2/sys/transport.h +++ b/include/git2/sys/transport.h @@ -30,8 +30,6 @@ typedef enum { GIT_TRANSPORTFLAGS_NONE = 0, } git_transport_flags_t; -typedef struct git_transport git_transport; - struct git_transport { unsigned int version; /* Set progress and error callbacks */ @@ -142,9 +140,6 @@ GIT_EXTERN(int) git_transport_new(git_transport **out, git_remote *owner, const */ GIT_EXTERN(int) git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *payload); -/* Signature of a function which creates a transport */ -typedef int (*git_transport_cb)(git_transport **out, git_remote *owner, void *param); - /** * Add a custom transport definition, to be used in addition to the built-in * set of transports that come with libgit2. @@ -353,21 +348,6 @@ GIT_EXTERN(int) git_smart_subtransport_ssh( git_transport* owner, void *param); -/** - * Sets a custom transport factory for the remote. The caller can use this - * function to override the transport used for this remote when performing - * network operations. - * - * @param remote the remote to configure - * @param transport_cb the function to use to create a transport - * @param payload opaque parameter passed to transport_cb - * @return 0 or an error code - */ -GIT_EXTERN(int) git_remote_set_transport( - git_remote *remote, - git_transport_cb transport_cb, - void *payload); - /** @} */ GIT_END_DECL #endif diff --git a/include/git2/transport.h b/include/git2/transport.h index c10907f5f..99fd09a1b 100644 --- a/include/git2/transport.h +++ b/include/git2/transport.h @@ -20,6 +20,9 @@ */ GIT_BEGIN_DECL +/** Signature of a function which creates a transport */ +typedef int (*git_transport_cb)(git_transport **out, git_remote *owner, void *param); + /** * Type of SSH host fingerprint */ diff --git a/include/git2/types.h b/include/git2/types.h index fdb5f2b09..d1e7cd92c 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -224,6 +224,12 @@ typedef struct git_refspec git_refspec; typedef struct git_remote git_remote; /** + * Interface which represents a transport to communicate with a + * remote. + */ +typedef struct git_transport git_transport; + +/** * Preparation for a push operation. Can be used to configure what to * push and the level of parallelism of the packfile builder. */ diff --git a/src/remote.c b/src/remote.c index a29b8aad9..95c316f54 100644 --- a/src/remote.c +++ b/src/remote.c @@ -309,8 +309,6 @@ int git_remote_dup(git_remote **dest, git_remote *source) GITERR_CHECK_ALLOC(remote->pushurl); } - remote->transport_cb = source->transport_cb; - remote->transport_cb_payload = source->transport_cb_payload; remote->repo = source->repo; remote->download_tags = source->download_tags; remote->update_fetchhead = source->update_fetchhead; @@ -725,13 +723,15 @@ int git_remote_connect(git_remote *remote, git_direction direction, const git_re int flags = GIT_TRANSPORTFLAGS_NONE; int error; void *payload = NULL; - git_cred_acquire_cb credentials; + git_cred_acquire_cb credentials = NULL; + git_transport_cb transport = NULL; assert(remote); if (callbacks) { GITERR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); credentials = callbacks->credentials; + transport = callbacks->transport; payload = callbacks->payload; } @@ -746,8 +746,8 @@ int git_remote_connect(git_remote *remote, git_direction direction, const git_re /* If we don't have a transport object yet, and the caller specified a * custom transport factory, use that */ - if (!t && remote->transport_cb && - (error = remote->transport_cb(&t, remote, remote->transport_cb_payload)) < 0) + if (!t && transport && + (error = transport(&t, remote, payload)) < 0) return error; /* If we still don't have a transport, then use the global @@ -1664,23 +1664,6 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo) return 0; } -int git_remote_set_transport( - git_remote *remote, - git_transport_cb transport_cb, - void *payload) -{ - assert(remote); - - if (remote->transport) { - giterr_set(GITERR_NET, "A transport is already bound to this remote"); - return -1; - } - - remote->transport_cb = transport_cb; - remote->transport_cb_payload = payload; - return 0; -} - const git_transfer_progress* git_remote_stats(git_remote *remote) { assert(remote); diff --git a/src/remote.h b/src/remote.h index 4fb2351d9..3a5c0dee4 100644 --- a/src/remote.h +++ b/src/remote.h @@ -24,8 +24,6 @@ struct git_remote { git_vector refspecs; git_vector active_refspecs; git_vector passive_refspecs; - git_transport_cb transport_cb; - void *transport_cb_payload; git_transport *transport; git_repository *repo; git_push *push; diff --git a/tests/clone/transport.c b/tests/clone/transport.c index 46c16a241..cccaae219 100644 --- a/tests/clone/transport.c +++ b/tests/clone/transport.c @@ -24,10 +24,9 @@ static int custom_transport_remote_create( { int error; - if ((error = git_remote_create(out, repo, name, url)) < 0) - return error; + GIT_UNUSED(payload); - if ((error = git_remote_set_transport(*out, custom_transport, payload)) < 0) + if ((error = git_remote_create(out, repo, name, url)) < 0) return error; return 0; @@ -40,7 +39,8 @@ void test_clone_transport__custom_transport(void) int custom_transport_used = 0; clone_opts.remote_cb = custom_transport_remote_create; - clone_opts.remote_cb_payload = &custom_transport_used; + clone_opts.fetch_opts.callbacks.transport = custom_transport; + clone_opts.fetch_opts.callbacks.payload = &custom_transport_used; cl_git_pass(git_clone(&repo, cl_fixture("testrepo.git"), "./custom_transport.git", &clone_opts)); git_repository_free(repo); diff --git a/tests/network/remote/remotes.c b/tests/network/remote/remotes.c index 8dbd68f2d..f31993710 100644 --- a/tests/network/remote/remotes.c +++ b/tests/network/remote/remotes.c @@ -80,6 +80,7 @@ void test_network_remote_remotes__error_when_not_found(void) void test_network_remote_remotes__error_when_no_push_available(void) { git_remote *r; + git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; char *specs = { "refs/heads/master", }; @@ -91,9 +92,8 @@ void test_network_remote_remotes__error_when_no_push_available(void) cl_git_pass(git_remote_create_anonymous(&r, _repo, cl_fixture("testrepo.git"), NULL)); - cl_git_pass(git_remote_set_transport(r, git_transport_local, NULL)); - - cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH, NULL)); + callbacks.transport = git_transport_local; + cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH, &callbacks)); /* Make sure that push is really not available */ r->transport->push = NULL; diff --git a/tests/online/clone.c b/tests/online/clone.c index 35ddbe9af..1d4196948 100644 --- a/tests/online/clone.c +++ b/tests/online/clone.c @@ -401,10 +401,9 @@ static int custom_remote_ssh_with_paths( { int error; - if ((error = git_remote_create(out, repo, name, url)) < 0) - return error; + GIT_UNUSED(payload); - if ((error = git_remote_set_transport(*out, git_transport_ssh_with_paths, payload)) < 0) + if ((error = git_remote_create(out, repo, name, url)) < 0) return error; return 0; @@ -435,7 +434,8 @@ void test_online_clone__ssh_with_paths(void) clar__skip(); g_options.remote_cb = custom_remote_ssh_with_paths; - g_options.remote_cb_payload = &arr; + g_options.fetch_opts.callbacks.transport = git_transport_ssh_with_paths; + g_options.fetch_opts.callbacks.payload = &arr; cl_git_fail(git_clone(&g_repo, remote_url, "./foo", &g_options)); diff --git a/tests/online/push_util.h b/tests/online/push_util.h index 83d46b506..822341bd2 100644 --- a/tests/online/push_util.h +++ b/tests/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, cred_acquire_cb, NULL, NULL, record_update_tips_cb, NULL, NULL, NULL, NULL, data } + { GIT_REMOTE_CALLBACKS_VERSION, NULL, NULL, cred_acquire_cb, NULL, NULL, record_update_tips_cb, NULL, NULL, NULL, NULL, NULL, data } typedef struct { char *name; |