@@ -89,46 +89,38 @@ static int cred_acquire_cb(
89
89
return -1 ;
90
90
}
91
91
92
- /* the results of a push status. when used for expected values, msg may be NULL
93
- * to indicate that it should not be matched. */
94
- typedef struct {
95
- const char * ref ;
96
- int success ;
97
- const char * msg ;
98
- } push_status ;
99
-
100
92
/**
101
93
* git_push_status_foreach callback that records status entries.
102
94
* @param data (git_vector *) of push_status instances
103
95
*/
104
- static int record_push_status_cb (const char * ref , const char * msg , void * data )
96
+ static int record_push_status_cb (const char * ref , const char * msg , void * payload )
105
97
{
106
- git_vector * statuses = (git_vector * )data ;
98
+ record_callbacks_data * data = (record_callbacks_data * ) payload ;
107
99
push_status * s ;
108
100
109
- cl_assert (s = git__malloc (sizeof (* s )));
110
- s -> ref = ref ;
101
+ cl_assert (s = git__calloc (1 , sizeof (* s )));
102
+ if (ref )
103
+ cl_assert (s -> ref = git__strdup (ref ));
111
104
s -> success = (msg == NULL );
112
- s -> msg = msg ;
105
+ if (msg )
106
+ cl_assert (s -> msg = git__strdup (msg ));
113
107
114
- git_vector_insert (statuses , s );
108
+ git_vector_insert (& data -> statuses , s );
115
109
116
110
return 0 ;
117
111
}
118
112
119
- static void do_verify_push_status (git_push * push , const push_status expected [], const size_t expected_len )
113
+ static void do_verify_push_status (record_callbacks_data * data , const push_status expected [], const size_t expected_len )
120
114
{
121
- git_vector actual = GIT_VECTOR_INIT ;
115
+ git_vector * actual = & data -> statuses ;
122
116
push_status * iter ;
123
117
bool failed = false;
124
118
size_t i ;
125
119
126
- git_push_status_foreach (push , record_push_status_cb , & actual );
127
-
128
- if (expected_len != actual .length )
120
+ if (expected_len != actual -> length )
129
121
failed = true;
130
122
else
131
- git_vector_foreach (& actual , i , iter )
123
+ git_vector_foreach (actual , i , iter )
132
124
if (strcmp (expected [i ].ref , iter -> ref ) ||
133
125
(expected [i ].success != iter -> success ) ||
134
126
(expected [i ].msg && (!iter -> msg || strcmp (expected [i ].msg , iter -> msg )))) {
@@ -149,7 +141,7 @@ static void do_verify_push_status(git_push *push, const push_status expected[],
149
141
150
142
git_buf_puts (& msg , "\nACTUAL:\n" );
151
143
152
- git_vector_foreach (& actual , i , iter ) {
144
+ git_vector_foreach (actual , i , iter ) {
153
145
if (iter -> success )
154
146
git_buf_printf (& msg , "%s: success\n" , iter -> ref );
155
147
else
@@ -161,10 +153,10 @@ static void do_verify_push_status(git_push *push, const push_status expected[],
161
153
git_buf_free (& msg );
162
154
}
163
155
164
- git_vector_foreach (& actual , i , iter )
156
+ git_vector_foreach (actual , i , iter )
165
157
git__free (iter );
166
158
167
- git_vector_free (& actual );
159
+ git_vector_free (actual );
168
160
}
169
161
170
162
/**
@@ -431,22 +423,24 @@ void test_online_push__cleanup(void)
431
423
static int push_pack_progress_cb (
432
424
int stage , unsigned int current , unsigned int total , void * payload )
433
425
{
434
- int * calls = (int * )payload ;
426
+ record_callbacks_data * data = (record_callbacks_data * ) payload ;
435
427
GIT_UNUSED (stage ); GIT_UNUSED (current ); GIT_UNUSED (total );
436
- if (* calls < 0 )
437
- return * calls ;
438
- (* calls )++ ;
428
+ if (data -> pack_progress_calls < 0 )
429
+ return data -> pack_progress_calls ;
430
+
431
+ data -> pack_progress_calls ++ ;
439
432
return 0 ;
440
433
}
441
434
442
435
static int push_transfer_progress_cb (
443
436
unsigned int current , unsigned int total , size_t bytes , void * payload )
444
437
{
445
- int * calls = (int * )payload ;
438
+ record_callbacks_data * data = (record_callbacks_data * ) payload ;
446
439
GIT_UNUSED (current ); GIT_UNUSED (total ); GIT_UNUSED (bytes );
447
- if (* calls < 0 )
448
- return * calls ;
449
- (* calls )++ ;
440
+ if (data -> transfer_progress_calls < 0 )
441
+ return data -> transfer_progress_calls ;
442
+
443
+ data -> transfer_progress_calls ++ ;
450
444
return 0 ;
451
445
}
452
446
@@ -466,62 +460,61 @@ static void do_push(
466
460
expected_ref expected_refs [], size_t expected_refs_len ,
467
461
int expected_ret , int check_progress_cb , int check_update_tips_cb )
468
462
{
469
- git_push * push ;
470
463
git_push_options opts = GIT_PUSH_OPTIONS_INIT ;
471
464
size_t i ;
472
- int pack_progress_calls = 0 , transfer_progress_calls = 0 ;
465
+ int error ;
466
+ git_strarray specs ;
473
467
git_signature * pusher ;
468
+ git_remote_callbacks callbacks ;
469
+ record_callbacks_data * data ;
474
470
475
471
if (_remote ) {
476
472
/* Auto-detect the number of threads to use */
477
473
opts .pb_parallelism = 0 ;
478
474
479
475
cl_git_pass (
git_signature_now (
& pusher ,
"Foo Bar" ,
"[email protected] " ));
480
- cl_git_pass (git_remote_connect (_remote , GIT_DIRECTION_PUSH ));
481
476
482
- cl_git_pass ( git_push_new ( & push , _remote ));
483
- cl_git_pass ( git_push_set_options ( push , & opts )) ;
477
+ memcpy ( & callbacks , git_remote_get_callbacks ( _remote ), sizeof ( callbacks ));
478
+ data = callbacks . payload ;
484
479
485
- if ( check_progress_cb ) {
486
- /* if EUSER, then abort in transfer */
487
- if ( expected_ret == GIT_EUSER )
488
- transfer_progress_calls = GIT_EUSER ;
480
+ callbacks . pack_progress = push_pack_progress_cb ;
481
+ callbacks . push_transfer_progress = push_transfer_progress_cb ;
482
+ callbacks . push_update_reference = record_push_status_cb ;
483
+ cl_git_pass ( git_remote_set_callbacks ( _remote , & callbacks )) ;
489
484
490
- cl_git_pass (
491
- git_push_set_callbacks (
492
- push , push_pack_progress_cb , & pack_progress_calls ,
493
- push_transfer_progress_cb , & transfer_progress_calls ));
494
- }
485
+ specs .count = refspecs_len ;
486
+ specs .strings = git__calloc (refspecs_len , sizeof (char * ));
487
+ cl_assert (specs .strings );
495
488
496
489
for (i = 0 ; i < refspecs_len ; i ++ )
497
- cl_git_pass (git_push_add_refspec (push , refspecs [i ]));
490
+ specs .strings [i ] = (char * ) refspecs [i ];
491
+
492
+ /* if EUSER, then abort in transfer */
493
+ if (check_progress_cb && expected_ret == GIT_EUSER )
494
+ data -> transfer_progress_calls = GIT_EUSER ;
495
+
496
+ error = git_remote_push (_remote , & specs , & opts , pusher , "test push" );
497
+ git__free (specs .strings );
498
498
499
499
if (expected_ret < 0 ) {
500
- cl_git_fail_with (git_push_finish (push ), expected_ret );
501
- cl_assert_equal_i (0 , git_push_unpack_ok (push ));
500
+ cl_git_fail_with (expected_ret , error );
502
501
} else {
503
- cl_git_pass (git_push_finish (push ));
504
- cl_assert_equal_i (1 , git_push_unpack_ok (push ));
502
+ cl_git_pass (error );
505
503
}
506
504
507
- if (check_progress_cb && ! expected_ret ) {
508
- cl_assert (pack_progress_calls > 0 );
509
- cl_assert (transfer_progress_calls > 0 );
505
+ if (check_progress_cb && expected_ret == 0 ) {
506
+ cl_assert (data -> pack_progress_calls > 0 );
507
+ cl_assert (data -> transfer_progress_calls > 0 );
510
508
}
511
509
512
- do_verify_push_status (push , expected_statuses , expected_statuses_len );
510
+ do_verify_push_status (data , expected_statuses , expected_statuses_len );
513
511
514
512
verify_refs (_remote , expected_refs , expected_refs_len );
515
-
516
- cl_git_pass (git_push_update_tips (push , pusher , "test push" ));
517
513
verify_tracking_branches (_remote , expected_refs , expected_refs_len );
518
514
519
515
if (check_update_tips_cb )
520
516
verify_update_tips_callback (_remote , expected_refs , expected_refs_len );
521
517
522
- git_push_free (push );
523
-
524
- git_remote_disconnect (_remote );
525
518
git_signature_free (pusher );
526
519
}
527
520
0 commit comments