summaryrefslogtreecommitdiff
path: root/src/push.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-12-24 15:14:38 -0600
committerEdward Thomson <ethomson@edwardthomson.com>2022-01-06 15:18:33 -0500
commit6fc6eeb66c40310086c8f059cae41de69ad4c6da (patch)
tree0c5453c41d0886abb5eb35faeb2a0d180da91a6d /src/push.c
parentf99a0d695c0a1a8e44fc1e5216d481ff016ec65d (diff)
downloadlibgit2-ethomson/remote_connect_opts.tar.gz
remote: introduce `git_remote_connect_options`ethomson/remote_connect_opts
The existing mechanism for providing options to remote fetch/push calls, and subsequently to transports, is unsatisfactory. It requires an options structure to avoid breaking the API and callback signatures. 1. Introduce `git_remote_connect_options` to satisfy those needs. 2. Add a new remote connection API, `git_remote_connect_ext` that will take this new options structure. Existing `git_remote_connect` calls will proxy to that. `git_remote_fetch` and `git_remote_push` will proxy their fetch/push options to that as well. 3. Define the interaction between `git_remote_connect` and fetch/push. Connect _may_ be called before fetch/push, but _need not_ be. The semantics of which options would be used for these operations was not specified if you specify options for both connect _and_ fetch. Now these are defined that the fetch or push options will be used _if_ they were specified. Otherwise, the connect options will be used if they were specified. Otherwise, the library's defaults will be used. 4. Update the transports to understand `git_remote_connect_options`. This is a breaking change to the systems API.
Diffstat (limited to 'src/push.c')
-rw-r--r--src/push.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/push.c b/src/push.c
index 9733eecf9..da8aebadd 100644
--- a/src/push.c
+++ b/src/push.c
@@ -29,19 +29,26 @@ static int push_status_ref_cmp(const void *a, const void *b)
return strcmp(push_status_a->ref, push_status_b->ref);
}
-int git_push_new(git_push **out, git_remote *remote)
+int git_push_new(git_push **out, git_remote *remote, const git_push_options *opts)
{
git_push *p;
*out = NULL;
+ GIT_ERROR_CHECK_VERSION(opts, GIT_PUSH_OPTIONS_VERSION, "git_push_options");
+
p = git__calloc(1, sizeof(*p));
GIT_ERROR_CHECK_ALLOC(p);
p->repo = remote->repo;
p->remote = remote;
p->report_status = 1;
- p->pb_parallelism = 1;
+ p->pb_parallelism = opts ? opts->pb_parallelism : 1;
+
+ if (opts) {
+ GIT_ERROR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
+ memcpy(&p->callbacks, &opts->callbacks, sizeof(git_remote_callbacks));
+ }
if (git_vector_init(&p->specs, 0, push_spec_rref_cmp) < 0) {
git__free(p);
@@ -65,20 +72,6 @@ int git_push_new(git_push **out, git_remote *remote)
return 0;
}
-int git_push_set_options(git_push *push, const git_push_options *opts)
-{
- if (!push || !opts)
- return -1;
-
- GIT_ERROR_CHECK_VERSION(opts, GIT_PUSH_OPTIONS_VERSION, "git_push_options");
-
- push->pb_parallelism = opts->pb_parallelism;
- push->connection.custom_headers = &opts->custom_headers;
- push->connection.proxy = &opts->proxy_opts;
-
- return 0;
-}
-
static void free_refspec(push_spec *spec)
{
if (spec == NULL)
@@ -411,10 +404,11 @@ static int calculate_work(git_push *push)
return 0;
}
-static int do_push(git_push *push, const git_remote_callbacks *callbacks)
+static int do_push(git_push *push)
{
int error = 0;
git_transport *transport = push->remote->transport;
+ git_remote_callbacks *callbacks = &push->callbacks;
if (!transport->push) {
git_error_set(GIT_ERROR_NET, "remote transport doesn't support push");
@@ -446,7 +440,7 @@ static int do_push(git_push *push, const git_remote_callbacks *callbacks)
goto on_error;
if ((error = queue_objects(push)) < 0 ||
- (error = transport->push(transport, push, callbacks)) < 0)
+ (error = transport->push(transport, push)) < 0)
goto on_error;
on_error:
@@ -472,7 +466,7 @@ static int filter_refs(git_remote *remote)
return 0;
}
-int git_push_finish(git_push *push, const git_remote_callbacks *callbacks)
+int git_push_finish(git_push *push)
{
int error;
@@ -482,7 +476,7 @@ int git_push_finish(git_push *push, const git_remote_callbacks *callbacks)
}
if ((error = filter_refs(push->remote)) < 0 ||
- (error = do_push(push, callbacks)) < 0)
+ (error = do_push(push)) < 0)
return error;
if (!push->unpack_ok) {