2
2
#include "php_git2_priv.h"
3
3
#include "remote.h"
4
4
5
+ static void php_git2_git_transfer_progress_to_array (git_transfer_progress * progress , zval * * out TSRMLS_DC )
6
+ {
7
+ zval * result ;
8
+
9
+ MAKE_STD_ZVAL (result );
10
+ array_init (result );
11
+
12
+ add_assoc_long_ex (result , ZEND_STRS ("total_objects" ), progress -> total_objects );
13
+ add_assoc_long_ex (result , ZEND_STRS ("indexed_objects" ), progress -> indexed_objects );
14
+ add_assoc_long_ex (result , ZEND_STRS ("received_objects" ), progress -> received_objects );
15
+ add_assoc_long_ex (result , ZEND_STRS ("local_objects" ), progress -> local_objects );
16
+ add_assoc_long_ex (result , ZEND_STRS ("total_deltas" ), progress -> total_deltas );
17
+ add_assoc_long_ex (result , ZEND_STRS ("indexed_deltas" ), progress -> indexed_deltas );
18
+ add_assoc_long_ex (result , ZEND_STRS ("received_bytes" ), progress -> received_bytes );
19
+
20
+ * out = result ;
21
+ }
22
+
23
+
5
24
/* {{{ proto resource git_remote_create(resource $repo, string $name, string $url)
6
25
*/
7
26
PHP_FUNCTION (git_remote_create )
@@ -312,19 +331,21 @@ PHP_FUNCTION(git_remote_get_fetch_refspecs)
312
331
PHP_FUNCTION (git_remote_set_fetch_refspecs )
313
332
{
314
333
int result = 0 ;
315
- zval * remote = NULL ;
334
+ zval * remote = NULL , * array = NULL ;
316
335
php_git2_t * _remote = NULL ;
317
- zval * array = NULL ;
318
336
int error = 0 ;
337
+ git_strarray out = {0 };
338
+
339
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
340
+ "ra" , & remote , & array ) == FAILURE ) {
341
+ return ;
342
+ }
319
343
320
- /* TODO(chobie): implement this */
321
- // if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
322
- // "r<git_strarray>", &remote, &array) == FAILURE) {
323
- // return;
324
- // }
344
+ php_git2_array_to_strarray (& out , array TSRMLS_CC );
325
345
326
346
ZEND_FETCH_RESOURCE (_remote , php_git2_t * , & remote , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
327
- result = git_remote_set_fetch_refspecs (PHP_GIT2_V (_remote , remote ), array );
347
+ result = git_remote_set_fetch_refspecs (PHP_GIT2_V (_remote , remote ), & out );
348
+ php_git2_strarray_free (& out );
328
349
RETURN_LONG (result );
329
350
}
330
351
/* }}} */
@@ -348,7 +369,7 @@ PHP_FUNCTION(git_remote_add_push)
348
369
349
370
ZEND_FETCH_RESOURCE (_remote , php_git2_t * , & remote , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
350
371
result = git_remote_add_push (PHP_GIT2_V (_remote , remote ), refspec );
351
- RETURN_BOOL (result );
372
+ RETURN_LONG (result );
352
373
}
353
374
/* }}} */
354
375
@@ -357,22 +378,22 @@ PHP_FUNCTION(git_remote_add_push)
357
378
PHP_FUNCTION (git_remote_get_push_refspecs )
358
379
{
359
380
zval * result ;
360
- git_strarray array = {0 };
361
- zval * remote = NULL ;
381
+ git_strarray _array = {0 };
382
+ zval * remote = NULL , * array = NULL ;
362
383
php_git2_t * _remote = NULL ;
363
384
int error = 0 ;
364
385
365
386
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
366
- "<git_strarray>r " , & array , & remote ) == FAILURE ) {
387
+ "ar " , & array , & remote ) == FAILURE ) {
367
388
return ;
368
389
}
369
390
391
+ php_git2_strarray_to_array (& _array , array TSRMLS_CC );
370
392
ZEND_FETCH_RESOURCE (_remote , php_git2_t * , & remote , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
371
- error = git_remote_get_push_refspecs (& array , PHP_GIT2_V (_remote , remote ));
372
- php_git2_strarray_to_array (& array , & result TSRMLS_CC );
373
- git_strarray_free (& array );
393
+ error = git_remote_get_push_refspecs (& _array , PHP_GIT2_V (_remote , remote ));
394
+ git_strarray_free (& _array );
374
395
375
- RETURN_ZVAL ( result , 0 , 1 );
396
+ RETURN_LONG ( error );
376
397
}
377
398
/* }}} */
378
399
@@ -382,19 +403,20 @@ PHP_FUNCTION(git_remote_get_push_refspecs)
382
403
PHP_FUNCTION (git_remote_set_push_refspecs )
383
404
{
384
405
int result = 0 ;
385
- zval * remote = NULL ;
406
+ zval * remote = NULL , * array = NULL ;
386
407
php_git2_t * _remote = NULL ;
387
- zval * array = NULL ;
408
+ git_strarray _array = { 0 } ;
388
409
int error = 0 ;
389
410
390
- /* TODO(chobie): implement this */
391
- // if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
392
- // "r<git_strarray>", &remote, &array) == FAILURE) {
393
- // return;
394
- // }
411
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
412
+ "r" , & remote , & array ) == FAILURE ) {
413
+ return ;
414
+ }
395
415
416
+ php_git2_strarray_to_array (& _array , array TSRMLS_CC );
396
417
ZEND_FETCH_RESOURCE (_remote , php_git2_t * , & remote , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
397
- result = git_remote_set_push_refspecs (PHP_GIT2_V (_remote , remote ), array );
418
+ result = git_remote_set_push_refspecs (PHP_GIT2_V (_remote , remote ), & _array );
419
+ git_strarray_free (& _array );
398
420
RETURN_LONG (result );
399
421
}
400
422
/* }}} */
@@ -443,7 +465,7 @@ PHP_FUNCTION(git_remote_get_refspec)
443
465
{
444
466
const git_refspec * result = NULL ;
445
467
zval * remote = NULL ;
446
- php_git2_t * _remote = NULL ;
468
+ php_git2_t * _remote = NULL , * out ;
447
469
long n = 0 ;
448
470
449
471
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
@@ -453,11 +475,13 @@ PHP_FUNCTION(git_remote_get_refspec)
453
475
454
476
ZEND_FETCH_RESOURCE (_remote , php_git2_t * , & remote , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
455
477
result = git_remote_get_refspec (PHP_GIT2_V (_remote , remote ), n );
456
- /* TODO(chobie): implement this */
478
+ if (php_git2_make_resource (& out , PHP_GIT2_TYPE_REFSPEC , result , 0 TSRMLS_CC )) {
479
+ RETURN_FALSE ;
480
+ }
481
+ ZVAL_RESOURCE (return_value , GIT2_RVAL_P (out ));
457
482
}
458
483
/* }}} */
459
484
460
-
461
485
/* {{{ proto bool git_remote_connect(resource $remote, long $direction)
462
486
*/
463
487
PHP_FUNCTION (git_remote_connect )
@@ -479,28 +503,59 @@ PHP_FUNCTION(git_remote_connect)
479
503
}
480
504
/* }}} */
481
505
482
- /* {{{ proto resource git_remote_ls(long $size, resource $remote)
506
+ static void php_git2_git_remote_head_to_array (git_remote_head * head , zval * * out TSRMLS_DC )
507
+ {
508
+ zval * result = NULL ;
509
+ char oid [41 ] = {0 }, loid [41 ] = {0 };
510
+
511
+
512
+ git_oid_fmt (oid , & head -> oid );
513
+ git_oid_fmt (loid , & head -> loid );
514
+
515
+ MAKE_STD_ZVAL (result );
516
+ array_init (result );
517
+ add_assoc_long_ex (result , ZEND_STRS ("local" ), head -> local );
518
+ add_assoc_string_ex (result , ZEND_STRS ("oid" ), oid , 1 );
519
+ add_assoc_string_ex (result , ZEND_STRS ("loid" ), loid , 1 );
520
+ add_assoc_string_ex (result , ZEND_STRS ("name" ), head -> name , 1 );
521
+
522
+ * out = result ;
523
+ }
524
+
525
+ /* {{{ proto resource git_remote_ls(resource $remote)
483
526
*/
484
527
PHP_FUNCTION (git_remote_ls )
485
528
{
486
529
php_git2_t * result = NULL ;
487
530
git_remote_head * * out = NULL ;
488
- long size = 0 ;
489
- zval * remote = NULL ;
531
+ size_t size = 0 ;
532
+ zval * remote = NULL , * retval = NULL , * container = NULL ;
490
533
php_git2_t * _remote = NULL ;
491
- int error = 0 ;
534
+ int error = 0 , i = 0 ;
492
535
493
536
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
494
- "lr" , & size , & remote ) == FAILURE ) {
537
+ "r" , & remote ) == FAILURE ) {
495
538
return ;
496
539
}
497
540
498
541
ZEND_FETCH_RESOURCE (_remote , php_git2_t * , & remote , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
499
- error = git_remote_ls (& out , size , PHP_GIT2_V (_remote , remote ));
542
+
543
+ if (git_remote_connected (PHP_GIT2_V (_remote , remote )) == 0 ) {
544
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "passed git_remote hasn't been connected" );
545
+ RETURN_FALSE ;
546
+ }
547
+ error = git_remote_ls (& out , & size , PHP_GIT2_V (_remote , remote ));
500
548
if (php_git2_check_error (error , "git_remote_ls" TSRMLS_CC )) {
501
549
RETURN_FALSE ;
502
550
}
503
- /* TODO(chobie): implement this */
551
+
552
+ MAKE_STD_ZVAL (container );
553
+ array_init (container );
554
+ for (i = 0 ; i < size ; i ++ ) {
555
+ php_git2_git_remote_head_to_array (out [i ], & retval TSRMLS_CC );
556
+ add_next_index_zval (container , retval );
557
+ }
558
+ RETURN_ZVAL (container , 0 , 1 );
504
559
}
505
560
/* }}} */
506
561
@@ -851,7 +906,7 @@ PHP_FUNCTION(git_remote_set_callbacks)
851
906
PHP_FUNCTION (git_remote_stats )
852
907
{
853
908
const git_transfer_progress * result = NULL ;
854
- zval * remote = NULL ;
909
+ zval * remote = NULL , * retval = NULL ;
855
910
php_git2_t * _remote = NULL ;
856
911
857
912
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
@@ -861,7 +916,8 @@ PHP_FUNCTION(git_remote_stats)
861
916
862
917
ZEND_FETCH_RESOURCE (_remote , php_git2_t * , & remote , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
863
918
result = git_remote_stats (PHP_GIT2_V (_remote , remote ));
864
- /* TODO(chobie): implement this */
919
+ php_git2_git_transfer_progress_to_array (result , & retval TSRMLS_CC );
920
+ RETURN_ZVAL (retval , 0 , 1 );
865
921
}
866
922
/* }}} */
867
923
@@ -881,7 +937,7 @@ PHP_FUNCTION(git_remote_autotag)
881
937
882
938
ZEND_FETCH_RESOURCE (_remote , php_git2_t * , & remote , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
883
939
result = git_remote_autotag (PHP_GIT2_V (_remote , remote ));
884
- /* TODO(chobie): implement this */
940
+ RETURN_LONG ( result );
885
941
}
886
942
/* }}} */
887
943
@@ -892,9 +948,8 @@ PHP_FUNCTION(git_remote_set_autotag)
892
948
zval * remote = NULL , * value = NULL ;
893
949
php_git2_t * _remote = NULL ;
894
950
895
- /* TODO(chobie):impelement this */
896
951
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
897
- "r<git_remote_autotag_option_t> " , & remote , & value ) == FAILURE ) {
952
+ "rl " , & remote , & value ) == FAILURE ) {
898
953
return ;
899
954
}
900
955
@@ -904,27 +959,39 @@ PHP_FUNCTION(git_remote_set_autotag)
904
959
/* }}} */
905
960
906
961
907
- /* {{{ proto long git_remote_rename(remote, new_name, callback, payload)
908
- */
962
+ static int php_git2_git_remote_rename_problem_cb (const char * problematic_refspec , void * payload )
963
+ {
964
+ return 0 ;
965
+ }
966
+
967
+
968
+ /* {{{ proto long git_remote_rename(resource $remote, string $new_name, Callable $callback, $payload)
969
+ */
909
970
PHP_FUNCTION (git_remote_rename )
910
971
{
911
- zval * remote ;
912
- php_git2_t * _remote ;
913
- char * new_name = {0 };
914
- int new_name_len ;
915
- zval * callback ;
916
- php_git2_t * _callback ;
972
+ int result = 0 , new_name_len = 0 , error = 0 ;
973
+ zval * remote = NULL , * callback = NULL , * payload = NULL ;
974
+ php_git2_t * _remote = NULL ;
975
+ char * new_name = NULL ;
976
+ zend_fcall_info fci = empty_fcall_info ;
977
+ zend_fcall_info_cache fcc = empty_fcall_info_cache ;
978
+ php_git2_cb_t * cb = NULL ;
917
979
918
- /* TODO(chobie): implement this */
919
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "git_remote_rename not implemented yet" );
920
- return ;
980
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
981
+ "rsfz" , & remote , & new_name , & new_name_len , & fci , & fcc , & payload ) == FAILURE ) {
982
+ return ;
983
+ }
921
984
922
- // if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
923
- // "rsr", &remote, &new_name, &new_name_len, &callback, &payload) == FAILURE) {
924
- // return;
925
- // }
926
- // ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
985
+ ZEND_FETCH_RESOURCE (_remote , php_git2_t * , & remote , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
986
+ if (php_git2_cb_init (& cb , & fci , & fcc , payload TSRMLS_CC )) {
987
+ RETURN_FALSE ;
988
+ }
989
+ result = git_remote_rename (PHP_GIT2_V (_remote , remote ), new_name , php_git2_git_remote_rename_problem_cb , cb );
990
+ php_git2_cb_free (cb );
991
+ RETURN_LONG (result );
927
992
}
993
+ /* }}} */
994
+
928
995
929
996
/* {{{ proto long git_remote_update_fetchhead(resource $remote)
930
997
*/
0 commit comments