mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-03 15:27:01 +00:00
Deploy GIT_REMOTE_CALLBACKS_INIT
This commit is contained in:
parent
55f6f21b7d
commit
9267ff586f
@ -70,7 +70,7 @@ int fetch(git_repository *repo, int argc, char **argv)
|
|||||||
const git_transfer_progress *stats;
|
const git_transfer_progress *stats;
|
||||||
pthread_t worker;
|
pthread_t worker;
|
||||||
struct dl_data data;
|
struct dl_data data;
|
||||||
git_remote_callbacks callbacks;
|
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
|
||||||
|
|
||||||
argc = argc;
|
argc = argc;
|
||||||
// Figure out whether it's a named remote or a URL
|
// Figure out whether it's a named remote or a URL
|
||||||
@ -81,7 +81,6 @@ int fetch(git_repository *repo, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set up the callbacks (only update_tips for now)
|
// Set up the callbacks (only update_tips for now)
|
||||||
memset(&callbacks, 0, sizeof(callbacks));
|
|
||||||
callbacks.update_tips = &update_cb;
|
callbacks.update_tips = &update_cb;
|
||||||
callbacks.progress = &progress_cb;
|
callbacks.progress = &progress_cb;
|
||||||
git_remote_set_callbacks(remote, &callbacks);
|
git_remote_set_callbacks(remote, &callbacks);
|
||||||
|
@ -356,8 +356,9 @@ struct git_remote_callbacks {
|
|||||||
*
|
*
|
||||||
* @param remote the remote to configure
|
* @param remote the remote to configure
|
||||||
* @param callbacks a pointer to the user's callback settings
|
* @param callbacks a pointer to the user's callback settings
|
||||||
|
* @return 0 or an error code
|
||||||
*/
|
*/
|
||||||
GIT_EXTERN(void) git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks);
|
GIT_EXTERN(int) git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the statistics structure that is filled in by the fetch operation.
|
* Get the statistics structure that is filled in by the fetch operation.
|
||||||
|
19
src/remote.c
19
src/remote.c
@ -985,10 +985,25 @@ void git_remote_check_cert(git_remote *remote, int check)
|
|||||||
remote->check_cert = check;
|
remote->check_cert = check;
|
||||||
}
|
}
|
||||||
|
|
||||||
void git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks)
|
static bool callbacks_have_valid_version(git_remote_callbacks *callbacks)
|
||||||
|
{
|
||||||
|
if (!callbacks)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (callbacks->version > 0 && callbacks->version <= GIT_REMOTE_CALLBACKS_VERSION)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
giterr_set(GITERR_INVALID, "Invalid version %d for git_remote_callbacks", callbacks->version);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks)
|
||||||
{
|
{
|
||||||
assert(remote && callbacks);
|
assert(remote && callbacks);
|
||||||
|
|
||||||
|
if (!callbacks_have_valid_version(callbacks))
|
||||||
|
return -1;
|
||||||
|
|
||||||
memcpy(&remote->callbacks, callbacks, sizeof(git_remote_callbacks));
|
memcpy(&remote->callbacks, callbacks, sizeof(git_remote_callbacks));
|
||||||
|
|
||||||
if (remote->transport && remote->transport->set_callbacks)
|
if (remote->transport && remote->transport->set_callbacks)
|
||||||
@ -996,6 +1011,8 @@ void git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callback
|
|||||||
remote->callbacks.progress,
|
remote->callbacks.progress,
|
||||||
NULL,
|
NULL,
|
||||||
remote->callbacks.payload);
|
remote->callbacks.payload);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void git_remote_set_cred_acquire_cb(
|
void git_remote_set_cred_acquire_cb(
|
||||||
|
@ -36,10 +36,9 @@ static void progress(const git_transfer_progress *stats, void *payload)
|
|||||||
static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n)
|
static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n)
|
||||||
{
|
{
|
||||||
git_remote *remote;
|
git_remote *remote;
|
||||||
git_remote_callbacks callbacks;
|
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
|
||||||
size_t bytes_received = 0;
|
size_t bytes_received = 0;
|
||||||
|
|
||||||
memset(&callbacks, 0, sizeof(git_remote_callbacks));
|
|
||||||
callbacks.update_tips = update_tips;
|
callbacks.update_tips = update_tips;
|
||||||
counter = 0;
|
counter = 0;
|
||||||
|
|
||||||
|
@ -11,7 +11,8 @@ extern const git_oid OID_ZERO;
|
|||||||
* record data in a record_callbacks_data instance.
|
* record data in a record_callbacks_data instance.
|
||||||
* @param data pointer to a record_callbacks_data instance
|
* @param data pointer to a record_callbacks_data instance
|
||||||
*/
|
*/
|
||||||
#define RECORD_CALLBACKS_INIT(data) { NULL, NULL, record_update_tips_cb, data }
|
#define RECORD_CALLBACKS_INIT(data) \
|
||||||
|
{ GIT_REMOTE_CALLBACKS_VERSION, NULL, NULL, record_update_tips_cb, data }
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *name;
|
char *name;
|
||||||
|
Loading…
Reference in New Issue
Block a user