Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2011-06-17 18:38:21 +0400
committerCarlos Martín Nieto <carlos@cmartin.tk>2011-06-26 22:43:45 +0400
commit4e913309b92138cdc6ff31fbce4e8afa2ab5458e (patch)
tree8f702228144d8877d8f3d064300c8fdd1491d7b3 /src/transport.c
parent0a9a38e539b02d254ec37ce6c18bdda2aedaafc8 (diff)
Move transports to an inheritance model
Rather than an 'private' pointer, make the private structures inherit from the generic git_transport struct. This way, we only have to worry about one memory allocation instead of two. The structures are so simple that this may even make the code use less memory overall. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Diffstat (limited to 'src/transport.c')
-rw-r--r--src/transport.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/transport.c b/src/transport.c
index fb0dc32c9..59aecb4cf 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -17,7 +17,7 @@ struct {
{NULL, 0}
};
-static git_transport_cb transport_fill_fn(const char *url)
+static git_transport_cb transport_new_fn(const char *url)
{
int i = 0;
@@ -43,7 +43,7 @@ static git_transport_cb transport_fill_fn(const char *url)
* Public API *
**************/
-int git_transport_dummy(git_transport *GIT_UNUSED(transport))
+int git_transport_dummy(git_transport **GIT_UNUSED(transport))
{
GIT_UNUSED_ARG(transport);
return git__throw(GIT_ENOTIMPLEMENTED, "This protocol isn't implemented. Sorry");
@@ -55,13 +55,11 @@ int git_transport_new(git_transport **out, git_repository *repo, const char *url
git_transport *transport;
int error;
- fn = transport_fill_fn(url);
+ fn = transport_new_fn(url);
- transport = git__malloc(sizeof(git_transport));
- if (transport == NULL)
- return GIT_ENOMEM;
-
- memset(transport, 0x0, sizeof(git_transport));
+ error = fn(&transport);
+ if (error < GIT_SUCCESS)
+ return git__rethrow(error, "Failed to create new transport");
transport->url = git__strdup(url);
if (transport->url == NULL)
@@ -69,10 +67,6 @@ int git_transport_new(git_transport **out, git_repository *repo, const char *url
transport->repo = repo;
- error = fn(transport);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to create new transport");
-
*out = transport;
return GIT_SUCCESS;