clone: put the callbacks struct directly in the clone options There's no need for this to be a pointer to somewhere else.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
diff --git a/examples/network/clone.c b/examples/network/clone.c
index f553c40..db35bd7 100644
--- a/examples/network/clone.c
+++ b/examples/network/clone.c
@@ -57,7 +57,6 @@ int do_clone(git_repository *repo, int argc, char **argv)
git_repository *cloned_repo = NULL;
git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
git_checkout_opts checkout_opts = GIT_CHECKOUT_OPTS_INIT;
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
const char *url = argv[1];
const char *path = argv[2];
int error;
@@ -75,10 +74,9 @@ int do_clone(git_repository *repo, int argc, char **argv)
checkout_opts.progress_cb = checkout_progress;
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.remote_callbacks.transfer_progress = &fetch_progress;
+ clone_opts.remote_callbacks.credentials = cred_acquire_cb;
+ clone_opts.remote_callbacks.payload = &pd;
// Do the clone
error = git_clone(&cloned_repo, url, path, &clone_opts);
diff --git a/include/git2/clone.h b/include/git2/clone.h
index a341a41..331cf92 100644
--- a/include/git2/clone.h
+++ b/include/git2/clone.h
@@ -49,7 +49,7 @@ typedef struct git_clone_options {
unsigned int version;
git_checkout_opts checkout_opts;
- git_remote_callbacks *remote_callbacks;
+ git_remote_callbacks remote_callbacks;
int bare;
int ignore_cert_errors;
@@ -58,7 +58,7 @@ typedef struct git_clone_options {
} git_clone_options;
#define GIT_CLONE_OPTIONS_VERSION 1
-#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION, {GIT_CHECKOUT_OPTS_VERSION, GIT_CHECKOUT_SAFE_CREATE}}
+#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION, {GIT_CHECKOUT_OPTS_VERSION, GIT_CHECKOUT_SAFE_CREATE}, GIT_REMOTE_CALLBACKS_INIT}
/**
* Clone a remote repository.
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 8145de1..9858634 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -457,7 +457,7 @@ struct git_remote_callbacks {
* @param callbacks a pointer to the user's callback settings
* @return 0 or an error code
*/
-GIT_EXTERN(int) git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks);
+GIT_EXTERN(int) git_remote_set_callbacks(git_remote *remote, const git_remote_callbacks *callbacks);
/**
* Get the statistics structure that is filled in by the fetch operation.
diff --git a/src/clone.c b/src/clone.c
index 1af6e39..f3e365c 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -315,8 +315,7 @@ static int create_and_configure_origin(
if (options->ignore_cert_errors)
git_remote_check_cert(origin, 0);
- if (options->remote_callbacks &&
- (error = git_remote_set_callbacks(origin, options->remote_callbacks)) < 0)
+ if ((error = git_remote_set_callbacks(origin, &options->remote_callbacks)) < 0)
goto on_error;
if ((error = git_remote_save(origin)) < 0)
diff --git a/src/remote.c b/src/remote.c
index ace8865..ccedf23 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -1153,7 +1153,7 @@ void git_remote_check_cert(git_remote *remote, int check)
remote->check_cert = check;
}
-int git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks)
+int git_remote_set_callbacks(git_remote *remote, const git_remote_callbacks *callbacks)
{
assert(remote && callbacks);
@@ -1162,7 +1162,7 @@ int git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks
memcpy(&remote->callbacks, callbacks, sizeof(git_remote_callbacks));
if (remote->transport && remote->transport->set_callbacks)
- remote->transport->set_callbacks(remote->transport,
+ return remote->transport->set_callbacks(remote->transport,
remote->callbacks.progress,
NULL,
remote->callbacks.payload);
diff --git a/tests-clar/clone/empty.c b/tests-clar/clone/empty.c
index d9dc24f..6d19244 100644
--- a/tests-clar/clone/empty.c
+++ b/tests-clar/clone/empty.c
@@ -10,12 +10,14 @@ static git_repository *g_repo_cloned;
void test_clone_empty__initialize(void)
{
git_repository *sandbox = cl_git_sandbox_init("empty_bare.git");
+ git_remote_callbacks dummy_callbacks = GIT_REMOTE_CALLBACKS_INIT;
cl_git_remove_placeholders(git_repository_path(sandbox), "dummy-marker.txt");
g_repo = NULL;
memset(&g_options, 0, sizeof(git_clone_options));
g_options.version = GIT_CLONE_OPTIONS_VERSION;
+ g_options.remote_callbacks = dummy_callbacks;
}
void test_clone_empty__cleanup(void)
diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c
index 9b666b3..4bcb5be 100644
--- a/tests-clar/clone/nonetwork.c
+++ b/tests-clar/clone/nonetwork.c
@@ -15,6 +15,7 @@ static git_remote* g_remote;
void test_clone_nonetwork__initialize(void)
{
git_checkout_opts dummy_opts = GIT_CHECKOUT_OPTS_INIT;
+ git_remote_callbacks dummy_callbacks = GIT_REMOTE_CALLBACKS_INIT;
g_repo = NULL;
@@ -22,6 +23,7 @@ void test_clone_nonetwork__initialize(void)
g_options.version = GIT_CLONE_OPTIONS_VERSION;
g_options.checkout_opts = dummy_opts;
g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+ g_options.remote_callbacks = dummy_callbacks;
}
void test_clone_nonetwork__cleanup(void)
diff --git a/tests-clar/online/clone.c b/tests-clar/online/clone.c
index 9a64ba1..4a6ade5 100644
--- a/tests-clar/online/clone.c
+++ b/tests-clar/online/clone.c
@@ -18,6 +18,7 @@ static git_clone_options g_options;
void test_online_clone__initialize(void)
{
git_checkout_opts dummy_opts = GIT_CHECKOUT_OPTS_INIT;
+ git_remote_callbacks dummy_callbacks = GIT_REMOTE_CALLBACKS_INIT;
g_repo = NULL;
@@ -25,6 +26,7 @@ void test_online_clone__initialize(void)
g_options.version = GIT_CLONE_OPTIONS_VERSION;
g_options.checkout_opts = dummy_opts;
g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+ g_options.remote_callbacks = dummy_callbacks;
}
void test_online_clone__cleanup(void)
@@ -100,15 +102,11 @@ void test_online_clone__can_checkout_a_cloned_repo(void)
bool checkout_progress_cb_was_called = false,
fetch_progress_cb_was_called = false;
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
-
g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
g_options.checkout_opts.progress_cb = &checkout_progress;
g_options.checkout_opts.progress_payload = &checkout_progress_cb_was_called;
-
- callbacks.transfer_progress = &fetch_progress;
- callbacks.payload = &fetch_progress_cb_was_called;
- g_options.remote_callbacks = &callbacks;
+ g_options.remote_callbacks.transfer_progress = &fetch_progress;
+ g_options.remote_callbacks.payload = &fetch_progress_cb_was_called;
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
@@ -175,12 +173,10 @@ static int update_tips(const char *refname, const git_oid *a, const git_oid *b,
void test_online_clone__custom_remote_callbacks(void)
{
- git_remote_callbacks remote_callbacks = GIT_REMOTE_CALLBACKS_INIT;
int callcount = 0;
- g_options.remote_callbacks = &remote_callbacks;
- remote_callbacks.update_tips = update_tips;
- remote_callbacks.payload = &callcount;
+ g_options.remote_callbacks.update_tips = update_tips;
+ g_options.remote_callbacks.payload = &callcount;
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
cl_assert(callcount > 0);
@@ -194,13 +190,11 @@ 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;
- callbacks.credentials = git_cred_userpass;
- callbacks.payload = &user_pass;
- g_options.remote_callbacks = &callbacks;
+ g_options.remote_callbacks.credentials = git_cred_userpass;
+ g_options.remote_callbacks.payload = &user_pass;
cl_git_pass(git_clone(&g_repo, remote_url, "./foo", &g_options));
git_repository_free(g_repo); g_repo = NULL;
@@ -213,11 +207,8 @@ void test_online_clone__bitbucket_style(void)
"libgit2", "libgit2"
};
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
-
- callbacks.credentials = git_cred_userpass;
- callbacks.payload = &user_pass;
- g_options.remote_callbacks = &callbacks;
+ g_options.remote_callbacks.credentials = git_cred_userpass;
+ g_options.remote_callbacks.payload = &user_pass;
cl_git_pass(git_clone(&g_repo, BB_REPO_URL, "./foo", &g_options));
git_repository_free(g_repo); g_repo = NULL;
@@ -247,10 +238,7 @@ static int cancel_at_half(const git_transfer_progress *stats, void *payload)
void test_online_clone__can_cancel(void)
{
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
-
- callbacks.transfer_progress = cancel_at_half;
- g_options.remote_callbacks = &callbacks;
+ g_options.remote_callbacks.transfer_progress = cancel_at_half;
cl_git_fail_with(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options), GIT_EUSER);
}
diff --git a/tests-clar/online/fetchhead.c b/tests-clar/online/fetchhead.c
index 5d9eb13..57b183f 100644
--- a/tests-clar/online/fetchhead.c
+++ b/tests-clar/online/fetchhead.c
@@ -12,10 +12,12 @@ static git_clone_options g_options;
void test_online_fetchhead__initialize(void)
{
+ git_remote_callbacks dummy_callbacks = GIT_REMOTE_CALLBACKS_INIT;
g_repo = NULL;
memset(&g_options, 0, sizeof(git_clone_options));
g_options.version = GIT_CLONE_OPTIONS_VERSION;
+ g_options.remote_callbacks = dummy_callbacks;
}
void test_online_fetchhead__cleanup(void)