|
1 | 1 | #include "php_git2.h"
|
| 2 | +#include "php_git2_priv.h" |
2 | 3 | #include "helper.h"
|
3 | 4 |
|
4 | 5 | static zval* datetime_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC)
|
@@ -135,3 +136,114 @@ void php_git2_strarray_to_array(git_strarray *array, zval **out TSRMLS_DC)
|
135 | 136 | }
|
136 | 137 | *out = result;
|
137 | 138 | }
|
| 139 | + |
| 140 | +int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, void *resource, int should_free TSRMLS_DC) |
| 141 | +{ |
| 142 | + php_git2_t *result = NULL; |
| 143 | + |
| 144 | + PHP_GIT2_MAKE_RESOURCE_NOCHECK(result); |
| 145 | + if (result == NULL) { |
| 146 | + return 1; |
| 147 | + } |
| 148 | + |
| 149 | + switch (type) { |
| 150 | + case PHP_GIT2_TYPE_REPOSITORY: |
| 151 | + PHP_GIT2_V(result, repository) = (git_repository*)resource; |
| 152 | + break; |
| 153 | + case PHP_GIT2_TYPE_COMMIT: |
| 154 | + PHP_GIT2_V(result, commit) = (git_commit*)resource; |
| 155 | + break; |
| 156 | + case PHP_GIT2_TYPE_TREE: |
| 157 | + PHP_GIT2_V(result, commit) = (git_tree*)resource; |
| 158 | + break; |
| 159 | + case PHP_GIT2_TYPE_TREE_ENTRY: |
| 160 | + PHP_GIT2_V(result, tree_entry) = (git_tree_entry*)resource; |
| 161 | + break; |
| 162 | + case PHP_GIT2_TYPE_BLOB: |
| 163 | + PHP_GIT2_V(result, blob) = (git_blob*)resource; |
| 164 | + break; |
| 165 | + case PHP_GIT2_TYPE_REVWALK: |
| 166 | + PHP_GIT2_V(result, revwalk) = (git_revwalk*)resource; |
| 167 | + break; |
| 168 | + case PHP_GIT2_TYPE_TREEBUILDER: |
| 169 | + PHP_GIT2_V(result, treebuilder) = (git_treebuilder*)resource; |
| 170 | + break; |
| 171 | + case PHP_GIT2_TYPE_REFERENCE: |
| 172 | + PHP_GIT2_V(result, reference) = (git_reference*)resource; |
| 173 | + break; |
| 174 | + case PHP_GIT2_TYPE_CONFIG: |
| 175 | + PHP_GIT2_V(result, config) = (git_config*)resource; |
| 176 | + break; |
| 177 | + case PHP_GIT2_TYPE_OBJECT: |
| 178 | + PHP_GIT2_V(result, object) = (git_object*)resource; |
| 179 | + break; |
| 180 | + case PHP_GIT2_TYPE_INDEX: |
| 181 | + PHP_GIT2_V(result, index) = (git_index*)resource; |
| 182 | + break; |
| 183 | + case PHP_GIT2_TYPE_ODB: |
| 184 | + PHP_GIT2_V(result, odb) = (git_odb*)resource; |
| 185 | + break; |
| 186 | + case PHP_GIT2_TYPE_REFDB: |
| 187 | + PHP_GIT2_V(result, refdb) = (git_refdb*)resource; |
| 188 | + break; |
| 189 | + case PHP_GIT2_TYPE_STATUS_LIST: |
| 190 | + PHP_GIT2_V(result, status_list) = (git_status_list*)resource; |
| 191 | + break; |
| 192 | + case PHP_GIT2_TYPE_BRANCH_ITERATOR: |
| 193 | + PHP_GIT2_V(result, branch_iterator) = (git_branch_iterator*)resource; |
| 194 | + break; |
| 195 | + case PHP_GIT2_TYPE_TAG: |
| 196 | + PHP_GIT2_V(result, tag) = (git_tag*)resource; |
| 197 | + break; |
| 198 | + case PHP_GIT2_TYPE_CRED: |
| 199 | + PHP_GIT2_V(result, cred) = (git_cred*)resource; |
| 200 | + break; |
| 201 | + case PHP_GIT2_TYPE_TRANSPORT: |
| 202 | + PHP_GIT2_V(result, transport) = (git_transport*)resource; |
| 203 | + break; |
| 204 | + case PHP_GIT2_TYPE_REMOTE: |
| 205 | + PHP_GIT2_V(result, remote) = (git_remote*)resource; |
| 206 | + break; |
| 207 | + case PHP_GIT2_TYPE_DIFF: |
| 208 | + PHP_GIT2_V(result, diff) = (git_diff*)resource; |
| 209 | + break; |
| 210 | + case PHP_GIT2_TYPE_MERGE_RESULT: |
| 211 | + PHP_GIT2_V(result, merge_result) = (git_merge_result*)resource; |
| 212 | + break; |
| 213 | + case PHP_GIT2_TYPE_MERGE_HEAD: |
| 214 | + PHP_GIT2_V(result, merge_head) = (git_merge_head*)resource; |
| 215 | + break; |
| 216 | + case PHP_GIT2_TYPE_PATHSPEC: |
| 217 | + PHP_GIT2_V(result, pathspec) = (git_pathspec*)resource; |
| 218 | + break; |
| 219 | + case PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST: |
| 220 | + PHP_GIT2_V(result, pathspec_match_list) = (git_pathspec_match_list*)resource; |
| 221 | + break; |
| 222 | + case PHP_GIT2_TYPE_PATCH: |
| 223 | + PHP_GIT2_V(result, patch) = (git_patch*)resource; |
| 224 | + break; |
| 225 | + case PHP_GIT2_TYPE_DIFF_HUNK: |
| 226 | + PHP_GIT2_V(result, diff_hunk) = (git_diff_hunk*)resource; |
| 227 | + break; |
| 228 | + case PHP_GIT2_TYPE_BUF: |
| 229 | + PHP_GIT2_V(result, buf) = (git_buf*)resource; |
| 230 | + break; |
| 231 | + case PHP_GIT2_TYPE_FILTER_LIST: |
| 232 | + PHP_GIT2_V(result, filter_list) = (git_filter_list*)resource; |
| 233 | + break; |
| 234 | + case PHP_GIT2_TYPE_FILTER_SOURCE: |
| 235 | + PHP_GIT2_V(result, filter_source) = (git_filter_source*)resource; |
| 236 | + break; |
| 237 | + case PHP_GIT2_TYPE_DIFF_LINE: |
| 238 | + PHP_GIT2_V(result, diff_line) = (git_diff_line*)resource; |
| 239 | + break; |
| 240 | + } |
| 241 | + |
| 242 | + result->type = type; |
| 243 | + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); |
| 244 | + result->should_free_v = should_free; |
| 245 | + |
| 246 | + *out = result; |
| 247 | + return 0; |
| 248 | +} |
| 249 | + |
0 commit comments