Commit fe3a40a4 by Carlos Martín Nieto

remote: add a convenience 'fetch' function.

parent d19870d9
...@@ -311,6 +311,17 @@ GIT_EXTERN(void) git_remote_free(git_remote *remote); ...@@ -311,6 +311,17 @@ GIT_EXTERN(void) git_remote_free(git_remote *remote);
GIT_EXTERN(int) git_remote_update_tips(git_remote *remote); GIT_EXTERN(int) git_remote_update_tips(git_remote *remote);
/** /**
* Download new data and update tips
*
* Convenience function to connect to a remote, download the data,
* disconnect and update the remote-tracking branches.
*
* @param remote the remote to fetch from
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_fetch(git_remote *remote);
/**
* Return whether a string is a valid remote URL * Return whether a string is a valid remote URL
* *
* @param url the url to check * @param url the url to check
......
...@@ -350,24 +350,6 @@ on_error: ...@@ -350,24 +350,6 @@ on_error:
return error; return error;
} }
static int do_fetch(git_remote *origin)
{
int retcode;
/* Connect and download everything */
if ((retcode = git_remote_connect(origin, GIT_DIRECTION_FETCH)) < 0)
return retcode;
if ((retcode = git_remote_download(origin)) < 0)
return retcode;
/* Create "origin/foo" branches for all remote branches */
if ((retcode = git_remote_update_tips(origin)) < 0)
return retcode;
return 0;
}
static int setup_remotes_and_fetch( static int setup_remotes_and_fetch(
git_repository *repo, git_repository *repo,
const char *url, const char *url,
...@@ -391,7 +373,7 @@ static int setup_remotes_and_fetch( ...@@ -391,7 +373,7 @@ static int setup_remotes_and_fetch(
((retcode = git_remote_add_fetch(origin, "refs/tags/*:refs/tags/*")) < 0)) ((retcode = git_remote_add_fetch(origin, "refs/tags/*:refs/tags/*")) < 0))
goto on_error; goto on_error;
if ((retcode = do_fetch(origin)) < 0) if ((retcode = git_remote_fetch(origin)) < 0)
goto on_error; goto on_error;
/* Point HEAD to the requested branch */ /* Point HEAD to the requested branch */
...@@ -459,7 +441,7 @@ int git_clone_into(git_repository *repo, git_remote *remote, git_checkout_opts * ...@@ -459,7 +441,7 @@ int git_clone_into(git_repository *repo, git_remote *remote, git_checkout_opts *
old_fetchhead = git_remote_update_fetchhead(remote); old_fetchhead = git_remote_update_fetchhead(remote);
git_remote_set_update_fetchhead(remote, 0); git_remote_set_update_fetchhead(remote, 0);
if ((error = do_fetch(remote)) < 0) if ((error = git_remote_fetch(remote)) < 0)
goto cleanup; goto cleanup;
if (branch) if (branch)
......
...@@ -767,6 +767,24 @@ int git_remote_download(git_remote *remote) ...@@ -767,6 +767,24 @@ int git_remote_download(git_remote *remote)
return git_fetch_download_pack(remote); return git_fetch_download_pack(remote);
} }
int git_remote_fetch(git_remote *remote)
{
int error;
/* Connect and download everything */
if ((error = git_remote_connect(remote, GIT_DIRECTION_FETCH)) < 0)
return error;
if ((error = git_remote_download(remote)) < 0)
return error;
/* We don't need to be connected anymore */
git_remote_disconnect(remote);
/* Create "remote/foo" branches for all remote branches */
return git_remote_update_tips(remote);
}
static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *update_heads, const char *fetchspec_src) static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *update_heads, const char *fetchspec_src)
{ {
unsigned int i; unsigned int i;
......
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