summaryrefslogtreecommitdiff
path: root/src/push.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-04-21 22:10:36 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-05-13 09:46:35 +0200
commit8f0104ecc54db00a075310ab744a19eb60e3d740 (patch)
tree775b3237a853c556a4d44840fc6c562e7b114415 /src/push.c
parent05259114427234831cf4915cbe40a5bb8ea021b0 (diff)
downloadlibgit2-8f0104ecc54db00a075310ab744a19eb60e3d740.tar.gz
Remove the callbacks struct from the remote
Having the setting be different from calling its actions was not a great idea and made for the sake of the wrong convenience. Instead of that, accept either fetch options, push options or the callbacks when dealing with the remote. The fetch options are currently only the callbacks, but more options will be moved from setters and getters on the remote to the options. This does mean passing the same struct along the different functions but the typical use-case will only call git_remote_fetch() or git_remote_push() and so won't notice much difference.
Diffstat (limited to 'src/push.c')
-rw-r--r--src/push.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/push.c b/src/push.c
index a4b61cd35..cd219e905 100644
--- a/src/push.c
+++ b/src/push.c
@@ -155,7 +155,7 @@ int git_push_add_refspec(git_push *push, const char *refspec)
return 0;
}
-int git_push_update_tips(git_push *push)
+int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
{
git_buf remote_ref_name = GIT_BUF_INIT;
size_t i, j;
@@ -212,9 +212,9 @@ int git_push_update_tips(git_push *push)
fire_callback = 0;
}
- if (fire_callback && push->remote->callbacks.update_tips) {
- error = push->remote->callbacks.update_tips(git_buf_cstr(&remote_ref_name),
- &push_spec->roid, &push_spec->loid, push->remote->callbacks.payload);
+ if (fire_callback && callbacks && callbacks->update_tips) {
+ error = callbacks->update_tips(git_buf_cstr(&remote_ref_name),
+ &push_spec->roid, &push_spec->loid, callbacks->payload);
if (error < 0)
goto on_error;
@@ -571,11 +571,10 @@ static int calculate_work(git_push *push)
return 0;
}
-static int do_push(git_push *push)
+static int do_push(git_push *push, const git_remote_callbacks *callbacks)
{
int error = 0;
git_transport *transport = push->remote->transport;
- git_remote_callbacks *cbs = &push->remote->callbacks;
if (!transport->push) {
giterr_set(GITERR_NET, "Remote transport doesn't support push");
@@ -594,20 +593,20 @@ static int do_push(git_push *push)
git_packbuilder_set_threads(push->pb, push->pb_parallelism);
- if (cbs->pack_progress)
- if ((error = git_packbuilder_set_callbacks(push->pb, cbs->pack_progress, cbs->payload)) < 0)
+ if (callbacks && callbacks->pack_progress)
+ if ((error = git_packbuilder_set_callbacks(push->pb, callbacks->pack_progress, callbacks->payload)) < 0)
goto on_error;
if ((error = calculate_work(push)) < 0)
goto on_error;
- if (cbs->push_negotiation &&
- (error = cbs->push_negotiation((const git_push_update **) push->updates.contents,
- push->updates.length, cbs->payload)) < 0)
+ if (callbacks && callbacks->push_negotiation &&
+ (error = callbacks->push_negotiation((const git_push_update **) push->updates.contents,
+ push->updates.length, callbacks->payload)) < 0)
goto on_error;
if ((error = queue_objects(push)) < 0 ||
- (error = transport->push(transport, push)) < 0)
+ (error = transport->push(transport, push, callbacks)) < 0)
goto on_error;
on_error:
@@ -633,16 +632,16 @@ static int filter_refs(git_remote *remote)
return 0;
}
-int git_push_finish(git_push *push)
+int git_push_finish(git_push *push, const git_remote_callbacks *callbacks)
{
int error;
if (!git_remote_connected(push->remote) &&
- (error = git_remote_connect(push->remote, GIT_DIRECTION_PUSH)) < 0)
+ (error = git_remote_connect(push->remote, GIT_DIRECTION_PUSH, callbacks)) < 0)
return error;
if ((error = filter_refs(push->remote)) < 0 ||
- (error = do_push(push)) < 0)
+ (error = do_push(push, callbacks)) < 0)
return error;
if (!push->unpack_ok) {