Don't expose the fetch code to the user Move the generation of the want-list to be done from the negotiate function, and keep the filtered references inside the remote structure. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 93bc834..207fe27 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -91,9 +91,12 @@ GIT_EXTERN(const git_refspec *) git_remote_pushspec(struct git_remote *remote);
/**
* Open a connection to a remote
*
- * The transport is selected based on the URL
+ * The transport is selected based on the URL. The direction argument
+ * is due to a limitation of the git protocol (over TCP or SSH) which
+ * starts up a specific binary which can only do the one or the other.
*
* @param remote the remote to connect to
+ * @param direction whether you want to receive or send data
* @return GIT_SUCCESS or an error code
*/
GIT_EXTERN(int) git_remote_connect(struct git_remote *remote, int direction);
@@ -110,6 +113,14 @@ GIT_EXTERN(int) git_remote_connect(struct git_remote *remote, int direction);
GIT_EXTERN(int) git_remote_ls(git_remote *remote, git_headarray *refs);
/**
+ * Negotiate what data needs to be exchanged to synchroize the remtoe
+ * and local references
+ *
+ * @param remote the remote you want to negotiate with
+ */
+GIT_EXTERN(int) git_remote_negotiate(git_remote *remote);
+
+/**
* Free the memory associated with a remote
*
* @param remote the remote to free
diff --git a/src/fetch.c b/src/fetch.c
index 5dc0440..b1da7a1 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -32,6 +32,7 @@
#include "transport.h"
#include "remote.h"
#include "refspec.h"
+#include "fetch.h"
/*
* Don't forget that this depends on the enum being correctly set
@@ -44,11 +45,7 @@ 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, we also want to be called from _negotiate
- */
-int git_fetch_list_want(git_headarray *whn_list, git_remote *remote)
+int filter_wants(git_remote *remote)
{
git_vector list;
git_headarray refs;
@@ -122,8 +119,8 @@ int git_fetch_list_want(git_headarray *whn_list, git_remote *remote)
}
git_vector_sort(&list);
- whn_list->len = list.length;
- whn_list->heads = (git_remote_head **) list.contents;
+ remote->refs.len = list.length;
+ remote->refs.heads = (git_remote_head **) list.contents;
return GIT_SUCCESS;
@@ -137,19 +134,24 @@ cleanup:
* them out. When we get an ACK we hide that commit and continue
* traversing until we're done
*/
-int git_fetch_negotiate(git_headarray *list, git_remote *remote)
+int git_fetch_negotiate(git_remote *remote)
{
git_revwalk *walk;
int error;
unsigned int i;
git_reference *ref;
git_strarray refs;
+ git_headarray *list = &remote->refs;
git_repository *repo = remote->repo;
git_oid oid;
+ error = filter_wants(remote);
+ if (error < GIT_SUCCESS)
+ return git__rethrow(error, "Failed to filter the reference list for wants");
+
/* Don't try to negotiate when we don't want anything */
if (list->len == 0)
- return GIT_EINVALIDARGS;
+ return GIT_SUCCESS;
/*
* Now we have everything set up so we can start tell the server
diff --git a/src/fetch.h b/src/fetch.h
new file mode 100644
index 0000000..2856f12
--- /dev/null
+++ b/src/fetch.h
@@ -0,0 +1,6 @@
+#ifndef INCLUDE_fetch_h__
+#define INCLUDE_fetch_h__
+
+int git_fetch_negotiate(git_remote *remote);
+
+#endif
diff --git a/src/remote.c b/src/remote.c
index 809bfbb..07628d8 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -30,6 +30,7 @@
#include "config.h"
#include "repository.h"
#include "remote.h"
+#include "fetch.h"
static int refspec_parse(git_refspec *refspec, const char *str)
{
@@ -202,6 +203,16 @@ int git_remote_ls(git_remote *remote, git_headarray *refs)
return git_transport_ls(remote->transport, refs);
}
+int git_remote_negotiate(git_remote *remote)
+{
+ return git_fetch_negotiate(remote);
+}
+
+git_headarray *git_remote_tips(git_remote *remote)
+{
+ return &remote->refs;
+}
+
void git_remote_free(git_remote *remote)
{
free(remote->fetch.src);
diff --git a/src/remote.h b/src/remote.h
index b94193c..f5686a2 100644
--- a/src/remote.h
+++ b/src/remote.h
@@ -8,6 +8,7 @@
struct git_remote {
char *name;
char *url;
+ git_headarray refs;
struct git_refspec fetch;
struct git_refspec push;
git_transport *transport;