Commit 10711769 by Ben Straub

Deploy versioned git_transport structure

parent 79cfa20d
......@@ -1024,10 +1024,25 @@ void git_remote_set_cred_acquire_cb(
remote->cred_acquire_cb = cred_acquire_cb;
}
static bool transport_has_valid_version(const git_transport *transport)
{
if (!transport)
return true;
if (transport->version > 0 && transport->version <= GIT_TRANSPORT_VERSION)
return true;
giterr_set(GITERR_INVALID, "Invalid version %d on git_transport", transport->version);
return false;
}
int git_remote_set_transport(git_remote *remote, git_transport *transport)
{
assert(remote && transport);
if (!transport_has_valid_version(transport))
return -1;
if (remote->transport) {
giterr_set(GITERR_NET, "A transport is already bound to this remote");
return -1;
......
......@@ -403,11 +403,10 @@ int git_transport_local(git_transport **out, git_remote *owner, void *param)
GIT_UNUSED(param);
t = git__malloc(sizeof(transport_local));
t = git__calloc(1, sizeof(transport_local));
GITERR_CHECK_ALLOC(t);
memset(t, 0x0, sizeof(transport_local));
t->parent.version = GIT_TRANSPORT_VERSION;
t->parent.connect = local_connect;
t->parent.negotiate_fetch = local_negotiate_fetch;
t->parent.download_pack = local_download_pack;
......
......@@ -303,6 +303,7 @@ int git_transport_smart(git_transport **out, git_remote *owner, void *param)
t = git__calloc(sizeof(transport_smart), 1);
GITERR_CHECK_ALLOC(t);
t->parent.version = GIT_TRANSPORT_VERSION;
t->parent.set_callbacks = git_smart__set_callbacks;
t->parent.connect = git_smart__connect;
t->parent.close = git_smart__close;
......
......@@ -279,3 +279,23 @@ void test_network_remotes__cannot_load_with_an_empty_url(void)
cl_git_fail(git_remote_load(&remote, _repo, "empty-remote-url"));
cl_assert(giterr_last()->klass == GITERR_INVALID);
}
void test_network_remotes__check_structure_version(void)
{
git_transport transport = GIT_TRANSPORT_INIT;
const git_error *err;
git_remote_free(_remote);
cl_git_pass(git_remote_new(&_remote, _repo, NULL, "test-protocol://localhost", NULL));
transport.version = 0;
cl_git_fail(git_remote_set_transport(_remote, &transport));
err = giterr_last();
cl_assert_equal_i(GITERR_INVALID, err->klass);
giterr_clear();
transport.version = 1024;
cl_git_fail(git_remote_set_transport(_remote, &transport));
err = giterr_last();
cl_assert_equal_i(GITERR_INVALID, err->klass);
}
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