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.
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
diff --git a/src/push.c b/src/push.c
index 3ac6fbf..a4b61cd 100644
--- a/src/push.c
+++ b/src/push.c
@@ -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 ||
diff --git a/src/push.h b/src/push.h
index fb5f014..fcba45c 100644
--- a/src/push.h
+++ b/src/push.h
@@ -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
diff --git a/src/remote.c b/src/remote.c
index 5257e85..91ebdd5 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -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;
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index f023db4..9e7b0a7 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -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;