Commit c5e07187 by Edward Thomson

Merge pull request #2990 from leoyanggit/custom_param

Add a custom param to git_smart_subtransport_definition
parents aa7a4a50 142e5379
...@@ -289,7 +289,8 @@ struct git_smart_subtransport { ...@@ -289,7 +289,8 @@ struct git_smart_subtransport {
/* A function which creates a new subtransport for the smart transport */ /* A function which creates a new subtransport for the smart transport */
typedef int (*git_smart_subtransport_cb)( typedef int (*git_smart_subtransport_cb)(
git_smart_subtransport **out, git_smart_subtransport **out,
git_transport* owner); git_transport* owner,
void* param);
/** /**
* Definition for a "subtransport" * Definition for a "subtransport"
...@@ -306,6 +307,10 @@ typedef struct git_smart_subtransport_definition { ...@@ -306,6 +307,10 @@ typedef struct git_smart_subtransport_definition {
* http:// is stateless, but git:// is not. * http:// is stateless, but git:// is not.
*/ */
unsigned rpc; unsigned rpc;
/** Param of the callback
*/
void* param;
} git_smart_subtransport_definition; } git_smart_subtransport_definition;
/* Smart transport subtransports that come with libgit2 */ /* Smart transport subtransports that come with libgit2 */
...@@ -321,7 +326,8 @@ typedef struct git_smart_subtransport_definition { ...@@ -321,7 +326,8 @@ typedef struct git_smart_subtransport_definition {
*/ */
GIT_EXTERN(int) git_smart_subtransport_http( GIT_EXTERN(int) git_smart_subtransport_http(
git_smart_subtransport **out, git_smart_subtransport **out,
git_transport* owner); git_transport* owner,
void *param);
/** /**
* Create an instance of the git subtransport. * Create an instance of the git subtransport.
...@@ -332,7 +338,8 @@ GIT_EXTERN(int) git_smart_subtransport_http( ...@@ -332,7 +338,8 @@ GIT_EXTERN(int) git_smart_subtransport_http(
*/ */
GIT_EXTERN(int) git_smart_subtransport_git( GIT_EXTERN(int) git_smart_subtransport_git(
git_smart_subtransport **out, git_smart_subtransport **out,
git_transport* owner); git_transport* owner,
void *param);
/** /**
* Create an instance of the ssh subtransport. * Create an instance of the ssh subtransport.
...@@ -343,7 +350,8 @@ GIT_EXTERN(int) git_smart_subtransport_git( ...@@ -343,7 +350,8 @@ GIT_EXTERN(int) git_smart_subtransport_git(
*/ */
GIT_EXTERN(int) git_smart_subtransport_ssh( GIT_EXTERN(int) git_smart_subtransport_ssh(
git_smart_subtransport **out, git_smart_subtransport **out,
git_transport* owner); git_transport* owner,
void *param);
/** /**
* Sets a custom transport factory for the remote. The caller can use this * Sets a custom transport factory for the remote. The caller can use this
......
...@@ -18,10 +18,10 @@ typedef struct transport_definition { ...@@ -18,10 +18,10 @@ typedef struct transport_definition {
void *param; void *param;
} transport_definition; } transport_definition;
static git_smart_subtransport_definition http_subtransport_definition = { git_smart_subtransport_http, 1 }; static git_smart_subtransport_definition http_subtransport_definition = { git_smart_subtransport_http, 1, NULL };
static git_smart_subtransport_definition git_subtransport_definition = { git_smart_subtransport_git, 0 }; static git_smart_subtransport_definition git_subtransport_definition = { git_smart_subtransport_git, 0, NULL };
#ifdef GIT_SSH #ifdef GIT_SSH
static git_smart_subtransport_definition ssh_subtransport_definition = { git_smart_subtransport_ssh, 0 }; static git_smart_subtransport_definition ssh_subtransport_definition = { git_smart_subtransport_ssh, 0, NULL };
#endif #endif
static transport_definition local_transport_definition = { "file://", git_transport_local, NULL }; static transport_definition local_transport_definition = { "file://", git_transport_local, NULL };
......
...@@ -341,10 +341,12 @@ static void _git_free(git_smart_subtransport *subtransport) ...@@ -341,10 +341,12 @@ static void _git_free(git_smart_subtransport *subtransport)
git__free(t); git__free(t);
} }
int git_smart_subtransport_git(git_smart_subtransport **out, git_transport *owner) int git_smart_subtransport_git(git_smart_subtransport **out, git_transport *owner, void *param)
{ {
git_subtransport *t; git_subtransport *t;
GIT_UNUSED(param);
if (!out) if (!out)
return -1; return -1;
......
...@@ -1008,10 +1008,12 @@ static void http_free(git_smart_subtransport *subtransport) ...@@ -1008,10 +1008,12 @@ static void http_free(git_smart_subtransport *subtransport)
git__free(t); git__free(t);
} }
int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *owner) int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *owner, void *param)
{ {
http_subtransport *t; http_subtransport *t;
GIT_UNUSED(param);
if (!out) if (!out)
return -1; return -1;
......
...@@ -409,7 +409,7 @@ int git_transport_smart(git_transport **out, git_remote *owner, void *param) ...@@ -409,7 +409,7 @@ int git_transport_smart(git_transport **out, git_remote *owner, void *param)
return -1; return -1;
} }
if (definition->callback(&t->wrapped, &t->parent) < 0) { if (definition->callback(&t->wrapped, &t->parent, definition->param) < 0) {
git__free(t); git__free(t);
return -1; return -1;
} }
......
...@@ -754,13 +754,15 @@ static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *use ...@@ -754,13 +754,15 @@ static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *use
#endif #endif
int git_smart_subtransport_ssh( int git_smart_subtransport_ssh(
git_smart_subtransport **out, git_transport *owner) git_smart_subtransport **out, git_transport *owner, void *param)
{ {
#ifdef GIT_SSH #ifdef GIT_SSH
ssh_subtransport *t; ssh_subtransport *t;
assert(out); assert(out);
GIT_UNUSED(param);
t = git__calloc(sizeof(ssh_subtransport), 1); t = git__calloc(sizeof(ssh_subtransport), 1);
GITERR_CHECK_ALLOC(t); GITERR_CHECK_ALLOC(t);
...@@ -773,6 +775,7 @@ int git_smart_subtransport_ssh( ...@@ -773,6 +775,7 @@ int git_smart_subtransport_ssh(
return 0; return 0;
#else #else
GIT_UNUSED(owner); GIT_UNUSED(owner);
GIT_UNUSED(param);
assert(out); assert(out);
*out = NULL; *out = NULL;
...@@ -793,6 +796,7 @@ int git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *p ...@@ -793,6 +796,7 @@ int git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *p
git_smart_subtransport_definition ssh_definition = { git_smart_subtransport_definition ssh_definition = {
git_smart_subtransport_ssh, git_smart_subtransport_ssh,
0, /* no RPC */ 0, /* no RPC */
NULL,
}; };
if (paths->count != 2) { if (paths->count != 2) {
......
...@@ -1327,10 +1327,12 @@ static void winhttp_free(git_smart_subtransport *subtransport) ...@@ -1327,10 +1327,12 @@ static void winhttp_free(git_smart_subtransport *subtransport)
git__free(t); git__free(t);
} }
int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *owner) int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *owner, void *param)
{ {
winhttp_subtransport *t; winhttp_subtransport *t;
GIT_UNUSED(param);
if (!out) if (!out)
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment