Commit 9ba49bb5 by Carlos Martín Nieto

Add git_remote_connect and git_remote_ls

These allow you to implement git-ls-remote when given a reference name
and a repository.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
parent c7c787ce
......@@ -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
......
......@@ -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);
}
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment