Commit e3c131c5 by Carlos Martín Nieto

remote: move the credentials callback to the struct

Move this one as well, letting us have a single way of setting the
callbacks for the remote, and removing fields from the clone options.
parent d31402a3
......@@ -76,9 +76,9 @@ int do_clone(git_repository *repo, int argc, char **argv)
checkout_opts.progress_payload = &pd;
clone_opts.checkout_opts = checkout_opts;
callbacks.transfer_progress = &fetch_progress;
callbacks.credentials = cred_acquire_cb;
callbacks.payload = &pd;
clone_opts.remote_callbacks = &callbacks;
clone_opts.cred_acquire_cb = cred_acquire_cb;
// Do the clone
error = git_clone(&cloned_repo, url, path, &clone_opts);
......
......@@ -91,8 +91,8 @@ int fetch(git_repository *repo, int argc, char **argv)
// Set up the callbacks (only update_tips for now)
callbacks.update_tips = &update_cb;
callbacks.progress = &progress_cb;
callbacks.credentials = cred_acquire_cb;
git_remote_set_callbacks(remote, &callbacks);
git_remote_set_cred_acquire_cb(remote, &cred_acquire_cb, NULL);
// Set up the information for the background worker thread
data.remote = remote;
......
......@@ -18,6 +18,7 @@ static int use_remote(git_repository *repo, char *name)
{
git_remote *remote = NULL;
int error;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
// Find the remote by name
error = git_remote_load(&remote, repo, name);
......@@ -27,7 +28,8 @@ static int use_remote(git_repository *repo, char *name)
goto cleanup;
}
git_remote_set_cred_acquire_cb(remote, &cred_acquire_cb, NULL);
callbacks.credentials = cred_acquire_cb;
git_remote_set_callbacks(remote, &callbacks);
error = git_remote_connect(remote, GIT_DIRECTION_FETCH);
if (error < 0)
......
......@@ -48,9 +48,6 @@ GIT_BEGIN_DECL
* results in the same behavior as GIT_REMOTE_DEFAULT_FETCH.
* - `push_spec` is the fetch specification to be used for pushing. NULL means
* use the same spec as for fetching.
* - `cred_acquire_cb` is a callback to be used if credentials are required
* during the initial fetch.
* - `cred_acquire_payload` is the payload for the above callback.
* - `transport_flags` is flags used to create transport if no transport is
* provided.
* - `transport` is a custom transport to be used for the initial fetch. NULL
......@@ -74,8 +71,6 @@ typedef struct git_clone_options {
const char *pushurl;
const char *fetch_spec;
const char *push_spec;
git_cred_acquire_cb cred_acquire_cb;
void *cred_acquire_payload;
git_transport_flags_t transport_flags;
git_transport *transport;
git_remote_callbacks *remote_callbacks;
......
......@@ -395,6 +395,7 @@ struct git_remote_callbacks {
unsigned int version;
void (*progress)(const char *str, int len, void *data);
int (*completion)(git_remote_completion_type type, void *data);
int (*credentials)(git_cred **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *data);
int (*transfer_progress)(const git_transfer_progress *stats, void *data);
int (*update_tips)(const char *refname, const git_oid *a, const git_oid *b, void *data);
void *payload;
......
......@@ -310,8 +310,6 @@ static int create_and_configure_origin(
if ((error = git_remote_create(&origin, repo, options->remote_name, url)) < 0)
goto on_error;
git_remote_set_cred_acquire_cb(origin, options->cred_acquire_cb,
options->cred_acquire_payload);
git_remote_set_autotag(origin, options->remote_autotag);
/*
* Don't write FETCH_HEAD, we'll check out the remote tracking
......
......@@ -591,7 +591,7 @@ int git_remote_connect(git_remote *remote, git_direction direction)
if (!remote->check_cert)
flags |= GIT_TRANSPORTFLAGS_NO_CHECK_CERT;
if (t->connect(t, url, remote->cred_acquire_cb, remote->cred_acquire_payload, direction, flags) < 0)
if (t->connect(t, url, remote->callbacks.credentials, remote->callbacks.payload, direction, flags) < 0)
goto on_error;
remote->transport = t;
......@@ -1152,17 +1152,6 @@ int git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks
return 0;
}
void git_remote_set_cred_acquire_cb(
git_remote *remote,
git_cred_acquire_cb cred_acquire_cb,
void *payload)
{
assert(remote);
remote->cred_acquire_cb = cred_acquire_cb;
remote->cred_acquire_payload = payload;
}
int git_remote_set_transport(git_remote *remote, git_transport *transport)
{
assert(remote && transport);
......
......@@ -21,8 +21,6 @@ struct git_remote {
char *pushurl;
git_vector refs;
git_vector refspecs;
git_cred_acquire_cb cred_acquire_cb;
void *cred_acquire_payload;
git_transport *transport;
git_repository *repo;
git_remote_callbacks callbacks;
......
......@@ -434,7 +434,7 @@ static int local_push(
if (!url || t->parent.close(&t->parent) < 0 ||
t->parent.connect(&t->parent, url,
push->remote->cred_acquire_cb, NULL, GIT_DIRECTION_PUSH, flags))
push->remote->callbacks.credentials, NULL, GIT_DIRECTION_PUSH, flags))
goto on_error;
}
......
......@@ -155,11 +155,13 @@ void test_online_clone__credentials(void)
cl_getenv("GITTEST_REMOTE_USER"),
cl_getenv("GITTEST_REMOTE_PASS")
};
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
if (!remote_url) return;
g_options.cred_acquire_cb = git_cred_userpass;
g_options.cred_acquire_payload = &user_pass;
callbacks.credentials = git_cred_userpass;
callbacks.payload = &user_pass;
g_options.remote_callbacks = &callbacks;
cl_git_pass(git_clone(&g_repo, remote_url, "./foo", &g_options));
git_repository_free(g_repo); g_repo = NULL;
......@@ -172,8 +174,11 @@ void test_online_clone__bitbucket_style(void)
"libgit2", "libgit2"
};
g_options.cred_acquire_cb = git_cred_userpass;
g_options.cred_acquire_payload = &user_pass;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
callbacks.credentials = git_cred_userpass;
callbacks.payload = &user_pass;
g_options.remote_callbacks = &callbacks;
cl_git_pass(git_clone(&g_repo, BB_REPO_URL, "./foo", &g_options));
git_repository_free(g_repo); g_repo = NULL;
......
......@@ -17,6 +17,8 @@ static char *_remote_url;
static char *_remote_user;
static char *_remote_pass;
static int cred_acquire_cb(git_cred **, const char *, const char *, unsigned int, void *);
static git_remote *_remote;
static bool _cred_acquire_called;
static record_callbacks_data _record_cbs_data = {{ 0 }};
......@@ -294,7 +296,6 @@ void test_online_push__initialize(void)
if (_remote_url) {
cl_git_pass(git_remote_create(&_remote, _repo, "test", _remote_url));
git_remote_set_cred_acquire_cb(_remote, cred_acquire_cb, &_cred_acquire_called);
record_callbacks_data_clear(&_record_cbs_data);
git_remote_set_callbacks(_remote, &_record_cbs);
......
......@@ -12,7 +12,7 @@ extern const git_oid OID_ZERO;
* @param data pointer to a record_callbacks_data instance
*/
#define RECORD_CALLBACKS_INIT(data) \
{ GIT_REMOTE_CALLBACKS_VERSION, NULL, NULL, NULL, record_update_tips_cb, data }
{ GIT_REMOTE_CALLBACKS_VERSION, NULL, NULL, cred_acquire_cb, NULL, record_update_tips_cb, data }
typedef struct {
char *name;
......
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