Commit 0ac2726fdf945792028e59105d8630a91c5d3663

Carlos Martín Nieto 2011-06-27T20:23:47

Slim down git_transport Remove the unused repo and private pointers and make the direction a flag, as it can only have two states. Change the connect signature to use an int instead of git_net_direction and remove that enum. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>

diff --git a/include/git2/net.h b/include/git2/net.h
index fb09eb5..4bef905 100644
--- a/include/git2/net.h
+++ b/include/git2/net.h
@@ -13,10 +13,8 @@
  * gets called.
  */
 
-enum git_net_direction {
-	INTENT_PUSH,
-	INTENT_PULL
-};
+#define GIT_DIR_FETCH 0
+#define GIT_DIR_PUSH 1
 
 /*
  * This is what we give out on ->ls()
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 9a988f3..03e4595 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -64,7 +64,7 @@ GIT_EXTERN(const git_refspec *) git_remote_fetchspec(struct git_remote *remote);
  * @param remote the remote to connect to
  * @return GIT_SUCCESS or an error code
  */
-GIT_EXTERN(int) git_remote_connect(struct git_remote *remote, git_net_direction dir);
+GIT_EXTERN(int) git_remote_connect(struct git_remote *remote, int direction);
 
 /**
  * Get a list of refs at the remote
diff --git a/include/git2/transport.h b/include/git2/transport.h
index 01883f2..982b081 100644
--- a/include/git2/transport.h
+++ b/include/git2/transport.h
@@ -45,7 +45,7 @@ GIT_BEGIN_DECL
  */
 GIT_EXTERN(int) git_transport_new(git_transport **transport, const char *url);
 
-GIT_EXTERN(int) git_transport_connect(git_transport *transport, git_net_direction direction);
+GIT_EXTERN(int) git_transport_connect(git_transport *transport, int direction);
 
 GIT_EXTERN(int) git_transport_ls(git_transport *transport, git_headarray *array);
 GIT_EXTERN(int) git_transport_close(git_transport *transport);
diff --git a/src/remote.c b/src/remote.c
index 59ea6a7..2812f5d 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -172,7 +172,7 @@ const git_refspec *git_remote_pushspec(struct git_remote *remote)
 	return &remote->push;
 }
 
-int git_remote_connect(git_remote *remote, git_net_direction dir)
+int git_remote_connect(git_remote *remote, int direction)
 {
 	int error;
 	git_transport *t;
@@ -181,7 +181,7 @@ int git_remote_connect(git_remote *remote, git_net_direction dir)
 	if (error < GIT_SUCCESS)
 		return git__rethrow(error, "Failed to create transport");
 
-	error = git_transport_connect(t, dir);
+	error = git_transport_connect(t, direction);
 	if (error < GIT_SUCCESS) {
 		error = git__rethrow(error, "Failed to connect the transport");
 		goto cleanup;
diff --git a/src/transport.c b/src/transport.c
index d71560b..204ef17 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -70,9 +70,9 @@ int git_transport_new(git_transport **out, const char *url)
 	return GIT_SUCCESS;
 }
 
-int git_transport_connect(git_transport *transport, git_net_direction dir)
+int git_transport_connect(git_transport *transport, int direction)
 {
-	return transport->connect(transport, dir);
+	return transport->connect(transport, direction);
 }
 
 int git_transport_ls(git_transport *transport, git_headarray *array)
diff --git a/src/transport.h b/src/transport.h
index 6d5f037..b17d9a9 100644
--- a/src/transport.h
+++ b/src/transport.h
@@ -32,22 +32,14 @@ struct git_transport {
 	 */
 	char *url;
 	/**
-	 * Where each transport stores its private/instance data
-	 */
-	void *private;
-	/**
-	 * The repo we want to act on
-	 */
-	git_repository *repo;
-	/**
 	 * Whether we want to push or fetch
 	 */
-	git_net_direction direction;
+	int direction : 1; /* 0 fetch, 1 push */
 	int connected : 1;
 	/**
 	 * Connect and store the remote heads
 	 */
-	int (*connect)(struct git_transport *transport, git_net_direction intent);
+	int (*connect)(struct git_transport *transport, int dir);
 	/**
 	 * Give a list of references, useful for ls-remote
 	 */
diff --git a/src/transport_git.c b/src/transport_git.c
index c7c8df0..d79ab5e 100644
--- a/src/transport_git.c
+++ b/src/transport_git.c
@@ -230,14 +230,15 @@ static int store_refs(transport_git *t)
  * Since this is a network connection, we need to parse and store the
  * pkt-lines at this stage and keep them there.
  */
-static int git_connect(git_transport *transport, git_net_direction direction)
+static int git_connect(git_transport *transport, int direction)
 {
 	transport_git *t = (transport_git *) transport;
 	int error = GIT_SUCCESS;
 
-	if (direction == INTENT_PUSH)
+	if (direction == GIT_DIR_PUSH)
 		return git__throw(GIT_EINVALIDARGS, "Pushing is not supported with the git protocol");
 
+	t->parent.direction = direction;
 	error = git_vector_init(&t->refs, 16, NULL);
 	if (error < GIT_SUCCESS)
 		goto cleanup;
diff --git a/src/transport_local.c b/src/transport_local.c
index 5dc5c26..bdb75ad 100644
--- a/src/transport_local.c
+++ b/src/transport_local.c
@@ -26,7 +26,7 @@ static int cmp_refs(const void *a, const void *b)
  * Try to open the url as a git directory. The direction doesn't
  * matter in this case because we're calulating the heads ourselves.
  */
-static int local_connect(git_transport *transport, git_net_direction GIT_UNUSED(dir))
+static int local_connect(git_transport *transport, int GIT_UNUSED(direction))
 {
 	git_repository *repo;
 	int error;