summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/git2/remote.h21
-rw-r--r--src/remote.c34
-rw-r--r--src/remote.h2
3 files changed, 57 insertions, 0 deletions
diff --git a/include/git2/remote.h b/include/git2/remote.h
index ccc130578..9a988f36c 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -57,6 +57,27 @@ GIT_EXTERN(const git_refspec *) git_remote_fetchspec(struct git_remote *remote);
GIT_EXTERN(const git_refspec *) git_remote_fetchspec(struct git_remote *remote);
/**
+ * Open a connection to a remote
+ *
+ * The transport is selected based on the URL
+ *
+ * @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);
+
+/**
+ * Get a list of refs at the remote
+ *
+ * The remote (or more exactly its transport) must be connected.
+ *
+ * @param refs where to store the refs
+ * @param remote the remote
+ * @return GIT_SUCCESS or an error code
+ */
+GIT_EXTERN(int) git_remote_ls(git_remote *remote, git_headarray *refs);
+
+/**
* Free the memory associated with a remote
*
* @param remote the remote to free
diff --git a/src/remote.c b/src/remote.c
index aa22debce..59ea6a797 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -172,6 +172,35 @@ 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 error;
+ git_transport *t;
+
+ error = git_transport_new(&t, remote->url);
+ if (error < GIT_SUCCESS)
+ return git__rethrow(error, "Failed to create transport");
+
+ error = git_transport_connect(t, dir);
+ if (error < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to connect the transport");
+ goto cleanup;
+ }
+
+ remote->transport = t;
+
+cleanup:
+ if (error < GIT_SUCCESS)
+ git_transport_free(t);
+
+ return error;
+}
+
+int git_remote_ls(git_remote *remote, git_headarray *refs)
+{
+ return git_transport_ls(remote->transport, refs);
+}
+
void git_remote_free(git_remote *remote)
{
free(remote->fetch.src);
@@ -180,5 +209,10 @@ void git_remote_free(git_remote *remote)
free(remote->push.dst);
free(remote->url);
free(remote->name);
+ if (remote->transport != NULL) {
+ if (remote->transport->connected)
+ git_transport_close(remote->transport);
+ git_transport_free(remote->transport);
+ }
free(remote);
}
diff --git a/src/remote.h b/src/remote.h
index afd2d1bb9..fdd6cd569 100644
--- a/src/remote.h
+++ b/src/remote.h
@@ -3,12 +3,14 @@
#include "remote.h"
#include "refspec.h"
+#include "transport.h"
struct git_remote {
char *name;
char *url;
struct git_refspec fetch;
struct git_refspec push;
+ git_transport *transport;
};
#endif