23
23
*/
24
24
25
25
#include "php_git2.h"
26
+ #include "ext/standard/php_smart_str.h"
26
27
27
28
PHPAPI zend_class_entry * git2_repository_class_entry ;
28
29
void php_git2_repository_init (TSRMLS_D );
@@ -527,6 +528,52 @@ PHP_METHOD(git2_repository, checkout)
527
528
/* }}} */
528
529
529
530
531
+ static int printer (
532
+ void * data ,
533
+ const git_diff_delta * delta ,
534
+ const git_diff_range * range ,
535
+ char usage ,
536
+ const char * line ,
537
+ size_t line_len )
538
+ {
539
+ smart_str * string = (smart_str * )data ;
540
+
541
+ smart_str_appendl (string , line , strlen (line ));
542
+ return 0 ;
543
+ }
544
+
545
+ /*
546
+ {{{ proto: Git2\Repository::diff(Git2\Tree $a, Git2\Tree $b, $options = NULL)
547
+ Experimental
548
+ */
549
+ PHP_METHOD (git2_repository , diff )
550
+ {
551
+ zval * old , * new ;
552
+ php_git2_tree * m_old , * m_new ;
553
+ php_git2_repository * m_repository ;
554
+ git_diff_list * list ;
555
+ smart_str string = {0 };
556
+
557
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
558
+ "OO" , & old , git2_tree_class_entry , & new , git2_tree_class_entry ) == FAILURE ) {
559
+ return ;
560
+ }
561
+
562
+ m_repository = PHP_GIT2_GET_OBJECT (php_git2_repository , getThis ());
563
+ m_old = PHP_GIT2_GET_OBJECT (php_git2_tree , old );
564
+ m_new = PHP_GIT2_GET_OBJECT (php_git2_tree , new );
565
+
566
+ git_diff_tree_to_tree (m_repository -> repository , NULL , m_old -> tree , m_new -> tree , & list );
567
+
568
+ git_diff_print_compact (list , & string , printer );
569
+ smart_str_0 (& string );
570
+ git_diff_list_free (list );
571
+
572
+ RETVAL_STRING (string .c , 0 );
573
+ }
574
+ /* }}} */
575
+
576
+
530
577
static zend_function_entry php_git2_repository_methods [] = {
531
578
PHP_ME (git2_repository , __construct , arginfo_git2_repository___construct , ZEND_ACC_PUBLIC | ZEND_ACC_CTOR )
532
579
PHP_ME (git2_repository , isEmpty , NULL , ZEND_ACC_PUBLIC )
@@ -542,6 +589,7 @@ static zend_function_entry php_git2_repository_methods[] = {
542
589
PHP_ME (git2_repository , write , arginfo_git2_repository_write , ZEND_ACC_PUBLIC )
543
590
PHP_ME (git2_repository , getMergeBase ,arginfo_git2_repository_get_merge_base ,ZEND_ACC_PUBLIC )
544
591
PHP_ME (git2_repository , checkout , arginfo_git2_repository_checkout , ZEND_ACC_PUBLIC )
592
+ PHP_ME (git2_repository , diff , NULL , ZEND_ACC_PUBLIC )
545
593
#ifdef lookup
546
594
#undef lookup
547
595
#endif
0 commit comments