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