*/
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.
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 */
*/
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.
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
*/
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
*/
*/
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.
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;
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;
}
/* 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
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);
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;
{
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;
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);
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",
};
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;
{
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;
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));
* @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;