Skip to content

Commit 21d549c

Browse files
committed
Changed callback initialization
The callbacks are initialized only if the caller had passed in the callback functions in the options hash
1 parent 276e25d commit 21d549c

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

ext/rugged/rugged_remote.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extern VALUE rb_cRuggedRepo;
2929
extern VALUE rb_eRuggedError;
3030
VALUE rb_cRuggedRemote;
3131

32-
#define RUGGED_REMOTE_CALLBACKS_INIT {1, progress_cb, NULL, credentials_cb, certificate_check_cb, transfer_progress_cb, update_tips_cb, NULL, NULL, push_update_reference_cb, NULL}
32+
#define RUGGED_REMOTE_CALLBACKS_INIT {1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, push_update_reference_cb, NULL}
3333

3434
static int progress_cb(const char *str, int len, void *data)
3535
{
@@ -184,6 +184,27 @@ static int credentials_cb(
184184
rb_raise(rb_eArgError, "Expected a Proc or an object that responds to #call (:" name " )."); \
185185
} while (0);
186186

187+
static void setup_callbacks(git_remote_callbacks *callbacks, VALUE rb_options)
188+
{
189+
if (NIL_P(rb_options))
190+
return;
191+
192+
if (!NIL_P(rb_hash_aref(rb_options, CSTR2SYM("progress"))))
193+
callbacks->sideband_progress = progress_cb;
194+
195+
if (!NIL_P(rb_hash_aref(rb_options, CSTR2SYM("credentials"))))
196+
callbacks->credentials = credentials_cb;
197+
198+
if (!NIL_P(rb_hash_aref(rb_options, CSTR2SYM("certificate_check"))))
199+
callbacks->certificate_check = certificate_check_cb;
200+
201+
if (!NIL_P(rb_hash_aref(rb_options, CSTR2SYM("transfer_progress"))))
202+
callbacks->transfer_progress = transfer_progress_cb;
203+
204+
if (!NIL_P(rb_hash_aref(rb_options, CSTR2SYM("update_tips"))))
205+
callbacks->update_tips = update_tips_cb;
206+
}
207+
187208
void rugged_remote_init_callbacks_and_payload_from_options(
188209
VALUE rb_options,
189210
git_remote_callbacks *callbacks,
@@ -193,6 +214,7 @@ void rugged_remote_init_callbacks_and_payload_from_options(
193214

194215
prefilled.payload = payload;
195216
memcpy(callbacks, &prefilled, sizeof(git_remote_callbacks));
217+
setup_callbacks(callbacks, rb_options);
196218

197219
if (!NIL_P(rb_options)) {
198220
CALLABLE_OR_RAISE(payload->certificate_check, rb_options, "certificate_check");

0 commit comments

Comments
 (0)