mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-28 15:58:29 +00:00
Add git_remote_update_tips
This function updates the references in the local reference storage to match the ones in the remote. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
This commit is contained in:
parent
c1af5a3935
commit
441f57c2b7
@ -141,6 +141,16 @@ GIT_EXTERN(int) git_remote_download(char **filename, git_remote *remote);
|
||||
*/
|
||||
GIT_EXTERN(void) git_remote_free(struct git_remote *remote);
|
||||
|
||||
/**
|
||||
* Update the tips to the new state
|
||||
*
|
||||
* Make sure that you only call this once you've successfully indexed
|
||||
* or expanded the packfile.
|
||||
*
|
||||
* @param remote the remote to update
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_update_tips(struct git_remote *remote);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
|
27
src/remote.c
27
src/remote.c
@ -31,6 +31,7 @@
|
||||
#include "repository.h"
|
||||
#include "remote.h"
|
||||
#include "fetch.h"
|
||||
#include "refs.h"
|
||||
|
||||
static int refspec_parse(git_refspec *refspec, const char *str)
|
||||
{
|
||||
@ -218,6 +219,32 @@ git_headarray *git_remote_tips(git_remote *remote)
|
||||
return &remote->refs;
|
||||
}
|
||||
|
||||
int git_remote_update_tips(struct git_remote *remote)
|
||||
{
|
||||
int error = GIT_SUCCESS;
|
||||
unsigned int i;
|
||||
char refname[GIT_PATH_MAX];
|
||||
git_headarray *refs = &remote->refs;
|
||||
git_remote_head *head;
|
||||
git_reference *ref;
|
||||
struct git_refspec *spec = &remote->fetch;
|
||||
|
||||
memset(refname, 0x0, sizeof(refname));
|
||||
|
||||
for (i = 0; i < refs->len; ++i) {
|
||||
head = refs->heads[i];
|
||||
error = git_refspec_transform(refname, sizeof(refname), spec, head->name);
|
||||
if (error < GIT_SUCCESS)
|
||||
return error;
|
||||
|
||||
error = git_reference_create_oid(&ref, remote->repo, refname, &head->oid, 1);
|
||||
if (error < GIT_SUCCESS)
|
||||
return error;
|
||||
}
|
||||
|
||||
return GIT_SUCCESS;
|
||||
}
|
||||
|
||||
void git_remote_free(git_remote *remote)
|
||||
{
|
||||
free(remote->fetch.src);
|
||||
|
Loading…
Reference in New Issue
Block a user