|
| 1 | +#include "php_git2.h" |
| 2 | +#include "git2_php_util.h" |
| 3 | + |
| 4 | +#define ARRAY_FETCH_LONG(_x) if ((data = zend_hash_str_find(ht, ZEND_STRL(#_x))) != NULL) { \ |
| 5 | + convert_to_long(data); \ |
| 6 | + opts->_x = Z_LVAL_P(data); \ |
| 7 | +} |
| 8 | + |
| 9 | +#define ARRAY_FETCH_BOOL(_x) if ((data = zend_hash_str_find(ht, ZEND_STRL(#_x))) != NULL) { \ |
| 10 | + convert_to_bool(data); \ |
| 11 | + opts->_x = Z_BVAL_P(data); \ |
| 12 | +} |
| 13 | + |
| 14 | +#define ARRAY_FETCH_STRING(_x) if ((data = zend_hash_str_find(ht, ZEND_STRL(#_x))) != NULL) { \ |
| 15 | + convert_to_string(data); \ |
| 16 | + opts->_x = Z_STRVAL_P(data); \ |
| 17 | +} |
| 18 | + |
| 19 | +#define ARRAY_FETCH_OPTIONS(_x, _method) if ((data = zend_hash_str_find(ht, ZEND_STRL(#_x))) != NULL) { \ |
| 20 | + convert_to_array(data); \ |
| 21 | + _method(&opts->_x, Z_ARRVAL_P(data)); \ |
| 22 | +} |
| 23 | + |
| 24 | +#define ARRAY_FETCH_STRARRAY(_x) ARRAY_FETCH_OPTIONS(_x, php_git2_ht_to_strarray) |
| 25 | + |
| 26 | +#define ARRAY_FETCH_CALLBACK(_x, _payload) /* TODO */ |
| 27 | + |
| 28 | +void php_git2_ht_to_strarray(git_strarray *out, HashTable *in) { |
| 29 | + uint32_t count = zend_array_count(in); |
| 30 | + out->count = count; |
| 31 | + if (count == 0) return; |
| 32 | + |
| 33 | + out->strings = emalloc(sizeof(char*) * count); |
| 34 | + uint32_t cur_pos = 0; |
| 35 | + |
| 36 | + HashPosition position; |
| 37 | + zval *data = NULL; |
| 38 | + |
| 39 | + for (zend_hash_internal_pointer_reset_ex(in, &position); |
| 40 | + data = zend_hash_get_current_data_ex(in, &position); |
| 41 | + zend_hash_move_forward_ex(in, &position)) { |
| 42 | + |
| 43 | + convert_to_string(data); |
| 44 | + out->strings[cur_pos] = Z_STRVAL_P(data); |
| 45 | + cur_pos += 1; |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +void php_git2_strarray_free(git_strarray *a) { |
| 50 | + if (a->count > 0) { |
| 51 | + efree(a->strings); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +void git2_parse_repository_init_options(git_repository_init_options *opts, HashTable *ht) { |
| 56 | + zval *data; |
| 57 | + |
| 58 | + if (ht == NULL) return; // skip if null |
| 59 | + |
| 60 | + ARRAY_FETCH_LONG(flags); |
| 61 | + ARRAY_FETCH_LONG(mode); |
| 62 | + ARRAY_FETCH_STRING(workdir_path); // check open_basedir? |
| 63 | + ARRAY_FETCH_STRING(description); |
| 64 | + ARRAY_FETCH_STRING(template_path); // check open_basedir? |
| 65 | + ARRAY_FETCH_STRING(initial_head); |
| 66 | + ARRAY_FETCH_STRING(origin_url); |
| 67 | +} |
| 68 | + |
| 69 | +void git2_parse_clone_options(git_clone_options *opts, HashTable *ht) { |
| 70 | + zval *data; |
| 71 | + |
| 72 | + if (ht == NULL) return; // skip if null |
| 73 | + |
| 74 | + ARRAY_FETCH_OPTIONS(checkout_opts, git2_parse_checkout_options); |
| 75 | + ARRAY_FETCH_OPTIONS(fetch_opts, git2_parse_fetch_options); |
| 76 | + ARRAY_FETCH_BOOL(bare); |
| 77 | + ARRAY_FETCH_LONG(local); // one of GIT_CLONE_LOCAL_AUTO, GIT_CLONE_LOCAL, GIT_CLONE_NO_LOCAL, GIT_CLONE_LOCAL_NO_LINKS |
| 78 | + ARRAY_FETCH_STRING(checkout_branch); |
| 79 | + ARRAY_FETCH_CALLBACK(repository_cb, repository_cb_payload); // TODO + _payload |
| 80 | + ARRAY_FETCH_CALLBACK(remote_cb, remote_cb_payload); // TODO + _payload |
| 81 | +} |
| 82 | + |
| 83 | +void git2_parse_checkout_options(git_checkout_options *opts, HashTable *ht) { |
| 84 | + zval *data; |
| 85 | + |
| 86 | + if (ht == NULL) return; // skip if null |
| 87 | + |
| 88 | + ARRAY_FETCH_LONG(checkout_strategy); |
| 89 | + ARRAY_FETCH_BOOL(disable_filters); |
| 90 | + ARRAY_FETCH_LONG(dir_mode); |
| 91 | + ARRAY_FETCH_LONG(file_mode); |
| 92 | + ARRAY_FETCH_LONG(file_open_flags); |
| 93 | + ARRAY_FETCH_LONG(notify_flags); |
| 94 | + ARRAY_FETCH_CALLBACK(notify_cb, notify_payload); |
| 95 | + ARRAY_FETCH_CALLBACK(progress_cb, progress_payload); |
| 96 | + ARRAY_FETCH_STRARRAY(paths); |
| 97 | + // git_tree *baseline; |
| 98 | + // git_index *baseline_index; |
| 99 | + ARRAY_FETCH_STRING(target_directory); |
| 100 | + ARRAY_FETCH_STRING(ancestor_label); |
| 101 | + ARRAY_FETCH_STRING(our_label); |
| 102 | + ARRAY_FETCH_STRING(their_label); |
| 103 | + ARRAY_FETCH_CALLBACK(perfdata_cb, perfdata_payload); |
| 104 | +} |
| 105 | + |
0 commit comments