mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-03 14:12:22 +00:00
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>
This commit is contained in:
parent
44daec4229
commit
e1d8803068
@ -91,9 +91,12 @@ GIT_EXTERN(const git_refspec *) git_remote_pushspec(struct git_remote *remote);
|
|||||||
/**
|
/**
|
||||||
* Open a connection to a 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 remote the remote to connect to
|
||||||
|
* @param direction whether you want to receive or send data
|
||||||
* @return GIT_SUCCESS or an error code
|
* @return GIT_SUCCESS or an error code
|
||||||
*/
|
*/
|
||||||
GIT_EXTERN(int) git_remote_connect(struct git_remote *remote, int direction);
|
GIT_EXTERN(int) git_remote_connect(struct git_remote *remote, int direction);
|
||||||
@ -109,6 +112,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);
|
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
|
* Free the memory associated with a remote
|
||||||
*
|
*
|
||||||
|
20
src/fetch.c
20
src/fetch.c
@ -32,6 +32,7 @@
|
|||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
#include "remote.h"
|
#include "remote.h"
|
||||||
#include "refspec.h"
|
#include "refspec.h"
|
||||||
|
#include "fetch.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Don't forget that this depends on the enum being correctly set
|
* 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;
|
return headb->type - heada->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
int filter_wants(git_remote *remote)
|
||||||
* 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)
|
|
||||||
{
|
{
|
||||||
git_vector list;
|
git_vector list;
|
||||||
git_headarray refs;
|
git_headarray refs;
|
||||||
@ -122,8 +119,8 @@ int git_fetch_list_want(git_headarray *whn_list, git_remote *remote)
|
|||||||
}
|
}
|
||||||
|
|
||||||
git_vector_sort(&list);
|
git_vector_sort(&list);
|
||||||
whn_list->len = list.length;
|
remote->refs.len = list.length;
|
||||||
whn_list->heads = (git_remote_head **) list.contents;
|
remote->refs.heads = (git_remote_head **) list.contents;
|
||||||
|
|
||||||
return GIT_SUCCESS;
|
return GIT_SUCCESS;
|
||||||
|
|
||||||
@ -137,19 +134,24 @@ cleanup:
|
|||||||
* them out. When we get an ACK we hide that commit and continue
|
* them out. When we get an ACK we hide that commit and continue
|
||||||
* traversing until we're done
|
* 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;
|
git_revwalk *walk;
|
||||||
int error;
|
int error;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
git_reference *ref;
|
git_reference *ref;
|
||||||
git_strarray refs;
|
git_strarray refs;
|
||||||
|
git_headarray *list = &remote->refs;
|
||||||
git_repository *repo = remote->repo;
|
git_repository *repo = remote->repo;
|
||||||
git_oid oid;
|
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 */
|
/* Don't try to negotiate when we don't want anything */
|
||||||
if (list->len == 0)
|
if (list->len == 0)
|
||||||
return GIT_EINVALIDARGS;
|
return GIT_SUCCESS;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now we have everything set up so we can start tell the server
|
* Now we have everything set up so we can start tell the server
|
||||||
|
6
src/fetch.h
Normal file
6
src/fetch.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef INCLUDE_fetch_h__
|
||||||
|
#define INCLUDE_fetch_h__
|
||||||
|
|
||||||
|
int git_fetch_negotiate(git_remote *remote);
|
||||||
|
|
||||||
|
#endif
|
11
src/remote.c
11
src/remote.c
@ -30,6 +30,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "repository.h"
|
#include "repository.h"
|
||||||
#include "remote.h"
|
#include "remote.h"
|
||||||
|
#include "fetch.h"
|
||||||
|
|
||||||
static int refspec_parse(git_refspec *refspec, const char *str)
|
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);
|
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)
|
void git_remote_free(git_remote *remote)
|
||||||
{
|
{
|
||||||
free(remote->fetch.src);
|
free(remote->fetch.src);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
struct git_remote {
|
struct git_remote {
|
||||||
char *name;
|
char *name;
|
||||||
char *url;
|
char *url;
|
||||||
|
git_headarray refs;
|
||||||
struct git_refspec fetch;
|
struct git_refspec fetch;
|
||||||
struct git_refspec push;
|
struct git_refspec push;
|
||||||
git_transport *transport;
|
git_transport *transport;
|
||||||
|
Loading…
Reference in New Issue
Block a user