@@ -29,8 +29,6 @@ extern VALUE rb_cRuggedRepo;
29
29
extern VALUE rb_eRuggedError ;
30
30
VALUE rb_cRuggedRemote ;
31
31
32
- #define RUGGED_REMOTE_CALLBACKS_INIT {1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, push_update_reference_cb, NULL}
33
-
34
32
static int progress_cb (const char * str , int len , void * data )
35
33
{
36
34
struct rugged_remote_cb_payload * payload = data ;
@@ -176,52 +174,50 @@ static int credentials_cb(
176
174
return payload -> exception ? GIT_ERROR : GIT_OK ;
177
175
}
178
176
179
- #define CALLABLE_OR_RAISE (ret , rb_options , name ) \
180
- do { \
181
- ret = rb_hash_aref(rb_options, CSTR2SYM(name)); \
182
- \
183
- if (!NIL_P(ret) && !rb_respond_to(ret, rb_intern("call"))) \
177
+ #define CALLABLE_OR_RAISE (ret , name ) \
178
+ do { \
179
+ if (!rb_respond_to(ret, rb_intern("call"))) \
184
180
rb_raise(rb_eArgError, "Expected a Proc or an object that responds to #call (:" name " )."); \
185
181
} while (0);
186
182
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
-
208
183
void rugged_remote_init_callbacks_and_payload_from_options (
209
184
VALUE rb_options ,
210
185
git_remote_callbacks * callbacks ,
211
186
struct rugged_remote_cb_payload * payload )
212
187
{
213
- git_remote_callbacks prefilled = RUGGED_REMOTE_CALLBACKS_INIT ;
214
-
215
- prefilled .payload = payload ;
216
- memcpy (callbacks , & prefilled , sizeof (git_remote_callbacks ));
217
- setup_callbacks (callbacks , rb_options );
188
+ callbacks -> payload = payload ;
189
+ callbacks -> push_update_reference = push_update_reference_cb ;
218
190
219
191
if (!NIL_P (rb_options )) {
220
- CALLABLE_OR_RAISE (payload -> certificate_check , rb_options , "certificate_check" );
221
- CALLABLE_OR_RAISE (payload -> update_tips , rb_options , "update_tips" );
222
- CALLABLE_OR_RAISE (payload -> progress , rb_options , "progress" );
223
- CALLABLE_OR_RAISE (payload -> transfer_progress , rb_options , "transfer_progress" );
224
- CALLABLE_OR_RAISE (payload -> credentials , rb_options , "credentials" );
192
+ payload -> progress = rb_hash_aref (rb_options , CSTR2SYM ("progress" ));
193
+ if (!NIL_P (payload -> progress )) {
194
+ CALLABLE_OR_RAISE (payload -> progress , "progress" );
195
+ callbacks -> sideband_progress = progress_cb ;
196
+ }
197
+
198
+ payload -> credentials = rb_hash_aref (rb_options , CSTR2SYM ("credentials" ));
199
+ if (!NIL_P (payload -> credentials )) {
200
+ CALLABLE_OR_RAISE (payload -> credentials , "credentials" );
201
+ callbacks -> credentials = credentials_cb ;
202
+ }
203
+
204
+ payload -> certificate_check = rb_hash_aref (rb_options , CSTR2SYM ("certificate_check" ));
205
+ if (!NIL_P (payload -> certificate_check )) {
206
+ CALLABLE_OR_RAISE (payload -> certificate_check , "certificate_check" );
207
+ callbacks -> certificate_check = certificate_check_cb ;
208
+ }
209
+
210
+ payload -> transfer_progress = rb_hash_aref (rb_options , CSTR2SYM ("transfer_progress" ));
211
+ if (!NIL_P (payload -> transfer_progress )) {
212
+ CALLABLE_OR_RAISE (payload -> transfer_progress , "transfer_progress" );
213
+ callbacks -> transfer_progress = transfer_progress_cb ;
214
+ }
215
+
216
+ payload -> update_tips = rb_hash_aref (rb_options , CSTR2SYM ("update_tips" ));
217
+ if (!NIL_P (payload -> update_tips )) {
218
+ CALLABLE_OR_RAISE (payload -> update_tips , "update_tips" );
219
+ callbacks -> update_tips = update_tips_cb ;
220
+ }
225
221
}
226
222
}
227
223
0 commit comments