Commit 0e20ba606655d25aa3fdeb9948a55e40107ac269

Carlos Martín Nieto 2011-07-30T18:56:20

Add a generic send_wants Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>

diff --git a/src/fetch.c b/src/fetch.c
index b9ddaf1..59beb1e 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -44,7 +44,10 @@ static int whn_cmp(const void *a, const void *b)
 	return headb->type - heada->type;
 }
 
-/* FIXME: we assume that the transport has been connected, enforce that somehow */
+/*
+ * FIXME: we assume that the transport has been connected, enforce
+ * that somehow, we also want to be called from _negotiate
+ */
 int git_fetch_list_want(git_headarray *whn_list, git_repository *repo, git_remote *remote)
 {
 	git_vector list;
@@ -179,7 +182,7 @@ int git_fetch_negotiate(git_headarray *list, git_repository *repo, git_remote *r
 	 * Now we have everything set up so we can start tell the server
 	 * what we want and what we have.
 	 */
-	git_pkt_send_wants(list);
+	git_remote_send_wants(remote, list);
 
 
 cleanup:
diff --git a/src/remote.c b/src/remote.c
index 2812f5d..997da00 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -31,6 +31,11 @@
 #include "repository.h"
 #include "remote.h"
 
+int git_remote_send_wants(git_remote *remote, git_headarray *list)
+{
+	return git_transport_send_wants(remote->transport, list);
+}
+
 static int refspec_parse(git_refspec *refspec, const char *str)
 {
 	char *delim;
diff --git a/src/remote.h b/src/remote.h
index fdd6cd5..e0c3fbf 100644
--- a/src/remote.h
+++ b/src/remote.h
@@ -13,4 +13,6 @@ struct git_remote {
 	git_transport *transport;
 };
 
+int git_remote_send_wants(git_remote *remote, git_headarray *list);
+
 #endif
diff --git a/src/transport.c b/src/transport.c
index 204ef17..96b79dd 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -80,6 +80,11 @@ int git_transport_ls(git_transport *transport, git_headarray *array)
 	return transport->ls(transport, array);
 }
 
+int git_transport_send_wants(struct git_transport *transport, git_headarray *array)
+{
+	return transport->send_wants(transport, array);
+}
+
 int git_transport_close(git_transport *transport)
 {
 	return transport->close(transport);
diff --git a/src/transport.h b/src/transport.h
index b17d9a9..9105ea4 100644
--- a/src/transport.h
+++ b/src/transport.h
@@ -57,6 +57,10 @@ struct git_transport {
 	 */
 	int (*push)(struct git_transport *transport);
 	/**
+	 * Send the list of 'want' refs
+	 */
+	int (*send_wants)(struct git_transport *transport, git_headarray *list);
+	/**
 	 * Fetch the changes
 	 */
 	int (*fetch)(struct git_transport *transport);
@@ -74,4 +78,6 @@ int git_transport_local(struct git_transport **transport);
 int git_transport_git(struct git_transport **transport);
 int git_transport_dummy(struct git_transport **transport);
 
+int git_transport_send_wants(struct git_transport *transport, git_headarray *array);
+
 #endif
diff --git a/src/transport_git.c b/src/transport_git.c
index b07b986..41b95ec 100644
--- a/src/transport_git.c
+++ b/src/transport_git.c
@@ -274,6 +274,13 @@ static int git_ls(git_transport *transport, git_headarray *array)
 	return GIT_SUCCESS;
 }
 
+static int git_send_wants(git_transport *transport, git_headarray *array)
+{
+	transport_git *t = (transport_git *) transport;
+
+	return git_pkt_send_wants(array, t->socket);
+}
+
 static int git_close(git_transport *transport)
 {
 	transport_git *t = (transport_git*) transport;
@@ -318,6 +325,7 @@ int git_transport_git(git_transport **out)
 
 	t->parent.connect = git_connect;
 	t->parent.ls = git_ls;
+	t->parent.send_wants = git_send_wants;
 	t->parent.close = git_close;
 	t->parent.free = git_free;
 
diff --git a/src/transport_local.c b/src/transport_local.c
index 4e0ac6f..b38679a 100644
--- a/src/transport_local.c
+++ b/src/transport_local.c
@@ -165,6 +165,15 @@ static int local_ls(git_transport *transport, git_headarray *array)
 	return error;
 }
 
+static int local_send_wants(git_transport *GIT_UNUSED(transport), git_headarray *GIT_UNUSED(array))
+{
+	GIT_UNUSED_ARG(tranport);
+	GIT_UNUSED_ARG(array);
+
+	/* We're local anyway, so we don't need this */
+	return GIT_SUCCESS;
+}
+
 static int local_close(git_transport *GIT_UNUSED(transport))
 {
 	/* Nothing to do */