Commit 05259114 by Carlos Martín Nieto

push: remove own copy of callbacks

The push object knows which remote it's associated with, and therefore
does not need to keep its own copy of the callbacks stored in the
remote.

Remove the copy and simply access the callbacks struct within the
remote.
parent f85a9c27
......@@ -77,30 +77,6 @@ int git_push_set_options(git_push *push, const git_push_options *opts)
return 0;
}
int git_push_set_callbacks(
git_push *push,
git_packbuilder_progress pack_progress_cb,
void *pack_progress_cb_payload,
git_push_transfer_progress transfer_progress_cb,
void *transfer_progress_cb_payload,
git_push_negotiation negotiation_cb,
void *negotiation_cb_payload)
{
if (!push)
return -1;
push->pack_progress_cb = pack_progress_cb;
push->pack_progress_cb_payload = pack_progress_cb_payload;
push->transfer_progress_cb = transfer_progress_cb;
push->transfer_progress_cb_payload = transfer_progress_cb_payload;
push->negotiation_cb = negotiation_cb;
push->negotiation_cb_payload = negotiation_cb_payload;
return 0;
}
static void free_refspec(push_spec *spec)
{
if (spec == NULL)
......@@ -599,6 +575,7 @@ static int do_push(git_push *push)
{
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");
......@@ -617,17 +594,16 @@ static int do_push(git_push *push)
git_packbuilder_set_threads(push->pb, push->pb_parallelism);
if (push->pack_progress_cb)
if ((error = git_packbuilder_set_callbacks(push->pb, push->pack_progress_cb, push->pack_progress_cb_payload)) < 0)
if (cbs->pack_progress)
if ((error = git_packbuilder_set_callbacks(push->pb, cbs->pack_progress, cbs->payload)) < 0)
goto on_error;
if ((error = calculate_work(push)) < 0)
goto on_error;
if (push->negotiation_cb &&
(error = push->negotiation_cb((const git_push_update **) push->updates.contents,
push->updates.length,
push->negotiation_cb_payload)))
if (cbs->push_negotiation &&
(error = cbs->push_negotiation((const git_push_update **) push->updates.contents,
push->updates.length, cbs->payload)) < 0)
goto on_error;
if ((error = queue_objects(push)) < 0 ||
......
......@@ -38,13 +38,6 @@ struct git_push {
/* options */
unsigned pb_parallelism;
git_packbuilder_progress pack_progress_cb;
void *pack_progress_cb_payload;
git_push_transfer_progress transfer_progress_cb;
void *transfer_progress_cb_payload;
git_push_negotiation negotiation_cb;
void *negotiation_cb_payload;
};
/**
......@@ -77,31 +70,6 @@ int git_push_set_options(
const git_push_options *opts);
/**
* Set the callbacks for a push
*
* @param push The push object
* @param pack_progress_cb Function to call with progress information during
* pack building. Be aware that this is called inline with pack building
* operations, so performance may be affected.
* @param pack_progress_cb_payload Payload for the pack progress callback.
* @param transfer_progress_cb Function to call with progress information during
* the upload portion of a push. Be aware that this is called inline with
* pack building operations, so performance may be affected.
* @param transfer_progress_cb_payload Payload for the network progress callback.
* @param push_negotiation_cb Function to call before sending the commands to the remote.
* @param push_negotiation_cb_payload Payload for the negotiation callback
* @return 0 or an error code
*/
int git_push_set_callbacks(
git_push *push,
git_packbuilder_progress pack_progress_cb,
void *pack_progress_cb_payload,
git_push_transfer_progress transfer_progress_cb,
void *transfer_progress_cb_payload,
git_push_negotiation negotiation_cb,
void *negotiation_cb_payload);
/**
* Add a refspec to be pushed
*
* @param push The push object
......
......@@ -2360,16 +2360,10 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
}
}
cbs = &remote->callbacks;
if ((error = git_push_set_callbacks(push,
cbs->pack_progress, cbs->payload,
cbs->push_transfer_progress, cbs->payload,
cbs->push_negotiation, cbs->payload)) < 0)
goto cleanup;
if ((error = git_push_finish(push)) < 0)
goto cleanup;
cbs = &remote->callbacks;
if (cbs->push_update_reference &&
(error = git_push_status_foreach(push, cbs->push_update_reference, cbs->payload)) < 0)
goto cleanup;
......
......@@ -950,6 +950,7 @@ int git_smart__push(git_transport *transport, git_push *push)
{
transport_smart *t = (transport_smart *)transport;
struct push_packbuilder_payload packbuilder_payload = {0};
git_remote_callbacks *cbs = &push->remote->callbacks;
git_buf pktline = GIT_BUF_INIT;
int error = 0, need_pack = 0;
push_spec *spec;
......@@ -957,9 +958,9 @@ int git_smart__push(git_transport *transport, git_push *push)
packbuilder_payload.pb = push->pb;
if (push->transfer_progress_cb) {
packbuilder_payload.cb = push->transfer_progress_cb;
packbuilder_payload.cb_payload = push->transfer_progress_cb_payload;
if (cbs->transfer_progress) {
packbuilder_payload.cb = cbs->push_transfer_progress;
packbuilder_payload.cb_payload = cbs->payload;
}
#ifdef PUSH_DEBUG
......@@ -1010,12 +1011,12 @@ int git_smart__push(git_transport *transport, git_push *push)
goto done;
/* If progress is being reported write the final report */
if (push->transfer_progress_cb) {
error = push->transfer_progress_cb(
if (cbs->push_transfer_progress) {
error = cbs->push_transfer_progress(
push->pb->nr_written,
push->pb->nr_objects,
packbuilder_payload.last_bytes,
push->transfer_progress_cb_payload);
cbs->payload);
if (error < 0)
goto done;
......
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