]> git.proxmox.com Git - libgit2.git/commitdiff
remote: move the transport ctor to the callbacks
authorCarlos Martín Nieto <cmn@dwim.me>
Wed, 22 Apr 2015 13:45:21 +0000 (15:45 +0200)
committerCarlos Martín Nieto <cmn@dwim.me>
Wed, 13 May 2015 07:46:36 +0000 (09:46 +0200)
Instead of having it set in a different place from every other callback,
put it the main structure. This removes some state from the remote and
makes it behave more like clone, where the constructors are passed via
the options.

include/git2/remote.h
include/git2/sys/transport.h
include/git2/transport.h
include/git2/types.h
src/remote.c
src/remote.h
tests/clone/transport.c
tests/network/remote/remotes.c
tests/online/clone.c
tests/online/push_util.h

index 41cf8512f69c7999d85a52b670fcf8fd8041c5b6..22aad5ad49e12773ffff4a0d4ef88b7a3ec13f28 100644 (file)
@@ -483,6 +483,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.
index d6ca8ff052812d7e3630d260656c45728a84e70e..867fbcbced8c81240f0b02fd8d0badbdc90bb573 100644 (file)
@@ -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
index c10907f5f63222e8fad895de34b577e9af02920c..99fd09a1b3bee6091fd518b93a9422b1d69af361 100644 (file)
@@ -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
  */
index fdb5f2b09b75a8071a571181e56b48c5a4cd0e61..d1e7cd92c67f68f7f8942208dbf4f24f64e8f732 100644 (file)
@@ -223,6 +223,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.
index a29b8aad9dbe75cfabc51fbcadfe5b23f73c5995..95c316f5442ae8b77e4672ad022f285927a10c94 100644 (file)
@@ -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);
index 4fb2351d90e3a85df8743961223b38f1b704bb2f..3a5c0dee4a0a3895b96a00490f46b3e4572940af 100644 (file)
@@ -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;
index 46c16a241b0d06efa2c050d6044d5f1efd3780cd..cccaae219b98a4e0b8e8db3b6f6e6c1f64aca7db 100644 (file)
@@ -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);
index 8dbd68f2d8e0b78d2feef92de620976b34fd8f96..f31993710034b9e62cc979a93349030a4b74134d 100644 (file)
@@ -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;
index 35ddbe9af5991491d602fe44cc8ae0e4f93f84fc..1d4196948390dcfa387ace8ed5958fcef6b97e0c 100644 (file)
@@ -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));
 
index 83d46b50646bcb65c03a523cd7f67c22c03bf780..822341bd269adc07d82114cfe2437c6e36f04f73 100644 (file)
@@ -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;