2
2
#include "php_git2_priv.h"
3
3
#include "blame.h"
4
4
5
+ static void php_git2_array_to_git_blame_options (git_blame_options * options , zval * array TSRMLS_DC )
6
+ {
7
+ zval * tmp ;
8
+
9
+ options -> version = php_git2_read_arrval_long (array , ZEND_STRS ("version" ) TSRMLS_CC );
10
+ options -> flags = php_git2_read_arrval_long (array , ZEND_STRS ("flags" ) TSRMLS_CC );
11
+ options -> min_match_characters = php_git2_read_arrval_long (array , ZEND_STRS ("min_match_characters" ) TSRMLS_CC );
12
+ tmp = php_git2_read_arrval (array , ZEND_STRS ("newest_commit" ) TSRMLS_CC );
13
+ if (Z_TYPE_P (tmp ) != NULL ) {
14
+ if (Z_TYPE_P (tmp ) != IS_STRING ) {
15
+ convert_to_string (tmp );
16
+ }
17
+ if (git_oid_fromstrn (& options -> newest_commit , Z_STRVAL_P (tmp ), Z_STRLEN_P (tmp )) != GIT_OK ) {
18
+ return ;
19
+ }
20
+ }
21
+
22
+ tmp = php_git2_read_arrval (array , ZEND_STRS ("oldest_commit" ) TSRMLS_CC );
23
+ if (Z_TYPE_P (tmp ) != NULL ) {
24
+ if (Z_TYPE_P (tmp ) != IS_STRING ) {
25
+ convert_to_string (tmp );
26
+ }
27
+ if (git_oid_fromstrn (& options -> newest_commit , Z_STRVAL_P (tmp ), Z_STRLEN_P (tmp )) != GIT_OK ) {
28
+ return ;
29
+ }
30
+ }
31
+
32
+ options -> min_line = php_git2_read_arrval_long (array , ZEND_STRS ("min_line" ) TSRMLS_CC );
33
+ options -> max_line = php_git2_read_arrval_long (array , ZEND_STRS ("max_line" ) TSRMLS_CC );
34
+
35
+ }
36
+
37
+ static void php_git2_git_blame_options_to_array (git_blame_options * options , zval * * out TSRMLS_DC )
38
+ {
39
+ zval * result = NULL ;
40
+ char buf [41 ] = {0 };
41
+
42
+ MAKE_STD_ZVAL (result );
43
+ array_init (result );
44
+
45
+ add_assoc_long_ex (result , ZEND_STRS ("version" ), options -> version );
46
+ add_assoc_long_ex (result , ZEND_STRS ("flags" ), options -> flags );
47
+ add_assoc_long_ex (result , ZEND_STRS ("min_match_characters" ), options -> min_match_characters );
48
+
49
+ if (git_oid_iszero (& options -> newest_commit ) != 1 ) {
50
+ git_oid_fmt (buf , & options -> newest_commit );
51
+ add_assoc_string_ex (result , ZEND_STRS ("newest_commit" ), out , 1 );
52
+ } else {
53
+ add_assoc_null_ex (result , ZEND_STRS ("newest_commit" ));
54
+ }
55
+
56
+ if (git_oid_iszero (& options -> oldest_commit ) != 1 ) {
57
+ git_oid_fmt (buf , & options -> oldest_commit );
58
+ add_assoc_string_ex (result , ZEND_STRS ("oldest_commit" ), out , 1 );
59
+ } else {
60
+ add_assoc_null_ex (result , ZEND_STRS ("oldest_commit" ));
61
+ }
62
+
63
+ add_assoc_long_ex (result , ZEND_STRS ("min_line" ), options -> min_line );
64
+ add_assoc_long_ex (result , ZEND_STRS ("max_line" ), options -> max_line );
65
+ * out = result ;
66
+ }
67
+
68
+ static void php_git2_git_blame_hunk_to_array (git_blame_hunk * hunk , zval * * out TSRMLS_DC )
69
+ {
70
+ zval * result = NULL , * final = NULL , * orig = NULL ;
71
+ char buf [41 ] = {0 };
72
+
73
+ MAKE_STD_ZVAL (result );
74
+ array_init (result );
75
+
76
+ add_assoc_long_ex (result , ZEND_STRS ("lines_in_hunk" ), hunk -> lines_in_hunk );
77
+
78
+ git_oid_fmt (buf , & hunk -> final_commit_id );
79
+ add_assoc_string_ex (result , ZEND_STRS ("final_commit_id" ), buf , 1 );
80
+
81
+ php_git2_signature_to_array (hunk -> final_signature , & final TSRMLS_CC );
82
+ add_assoc_zval_ex (result , ZEND_STRS ("final_signature" ), final );
83
+
84
+ add_assoc_long_ex (result , ZEND_STRS ("final_start_line_number" ), hunk -> final_start_line_number );
85
+
86
+ git_oid_fmt (buf , & hunk -> orig_commit_id );
87
+ add_assoc_string_ex (result , ZEND_STRS ("orig_commit_id" ), buf , 1 );
88
+ add_assoc_string_ex (result , ZEND_STRS ("orig_path" ), hunk -> orig_path , 1 );
89
+
90
+ add_assoc_long_ex (result , ZEND_STRS ("orig_start_line_number" ), hunk -> orig_start_line_number );
91
+ if (hunk -> orig_signature ) {
92
+ php_git2_signature_to_array (hunk -> orig_signature , & orig TSRMLS_CC );
93
+ } else {
94
+ MAKE_STD_ZVAL (orig );
95
+ ZVAL_NULL (orig );
96
+ }
97
+ add_assoc_zval_ex (result , ZEND_STRS ("orig_signature" ), orig );
98
+
99
+ add_assoc_stringl_ex (result , ZEND_STRS ("boundary" ), & hunk -> boundary , 1 , 1 );
100
+
101
+ * out = result ;
102
+ }
103
+
5
104
/* {{{ proto long git_blame_get_hunk_count(resource $blame)
6
105
*/
7
106
PHP_FUNCTION (git_blame_get_hunk_count )
@@ -26,7 +125,7 @@ PHP_FUNCTION(git_blame_get_hunk_count)
26
125
PHP_FUNCTION (git_blame_get_hunk_byindex )
27
126
{
28
127
const git_blame_hunk * result = NULL ;
29
- zval * blame = NULL ;
128
+ zval * blame = NULL , * array = NULL ;
30
129
php_git2_t * _blame = NULL ;
31
130
long index = 0 ;
32
131
@@ -37,7 +136,11 @@ PHP_FUNCTION(git_blame_get_hunk_byindex)
37
136
38
137
ZEND_FETCH_RESOURCE (_blame , php_git2_t * , & blame , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
39
138
result = git_blame_get_hunk_byindex (PHP_GIT2_V (_blame , blame ), index );
40
- /* TODO(chobie): implement this */
139
+ if (result == NULL ) {
140
+ RETURN_FALSE ;
141
+ }
142
+ php_git2_git_blame_hunk_to_array (result , & array TSRMLS_CC );
143
+ RETURN_ZVAL (array , 0 , 1 );
41
144
}
42
145
/* }}} */
43
146
@@ -46,7 +149,7 @@ PHP_FUNCTION(git_blame_get_hunk_byindex)
46
149
PHP_FUNCTION (git_blame_get_hunk_byline )
47
150
{
48
151
const git_blame_hunk * result = NULL ;
49
- zval * blame = NULL ;
152
+ zval * blame = NULL , * array = NULL ;
50
153
php_git2_t * _blame = NULL ;
51
154
long lineno = 0 ;
52
155
@@ -57,7 +160,11 @@ PHP_FUNCTION(git_blame_get_hunk_byline)
57
160
58
161
ZEND_FETCH_RESOURCE (_blame , php_git2_t * , & blame , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
59
162
result = git_blame_get_hunk_byline (PHP_GIT2_V (_blame , blame ), lineno );
60
- /* TODO(chobie): implement this */
163
+ if (result == NULL ) {
164
+ RETURN_FALSE ;
165
+ }
166
+ php_git2_git_blame_hunk_to_array (result , & array TSRMLS_CC );
167
+ RETURN_ZVAL (array , 0 , 1 );
61
168
}
62
169
/* }}} */
63
170
@@ -68,16 +175,18 @@ PHP_FUNCTION(git_blame_file)
68
175
php_git2_t * result = NULL , * _repo = NULL ;
69
176
git_blame * out = NULL ;
70
177
zval * repo = NULL , * options = NULL ;
178
+ git_blame_options opts = GIT_BLAME_OPTIONS_INIT ;
71
179
char * path = NULL ;
72
180
int path_len = 0 , error = 0 ;
73
181
74
182
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
75
- "rs<git_blame_options> " , & repo , & path , & path_len , & options ) == FAILURE ) {
183
+ "rsa " , & repo , & path , & path_len , & options ) == FAILURE ) {
76
184
return ;
77
185
}
78
-
186
+
79
187
ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
80
- error = git_blame_file (& out , PHP_GIT2_V (_repo , repository ), path , options );
188
+ php_git2_array_to_git_blame_options (& opts , options TSRMLS_CC );
189
+ error = git_blame_file (& out , PHP_GIT2_V (_repo , repository ), path , & opts );
81
190
if (php_git2_check_error (error , "git_blame_file" TSRMLS_CC )) {
82
191
RETURN_FALSE ;
83
192
}
@@ -136,3 +245,14 @@ PHP_FUNCTION(git_blame_free)
136
245
}
137
246
/* }}} */
138
247
248
+ /* {{{ proto void git_blame_options_new()
249
+ */
250
+ PHP_FUNCTION (git_blame_options_new )
251
+ {
252
+ zval * result ;
253
+ git_blame_options options = GIT_BLAME_OPTIONS_INIT ;
254
+
255
+ php_git2_git_blame_options_to_array (& options , & result TSRMLS_CC );
256
+ RETURN_ZVAL (result , 0 , 1 );
257
+ }
258
+ /* }}} */
0 commit comments