From 39e7b888df5666c8b50aff74bd3d3565c19d1414 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 13:01:44 +0900 Subject: [PATCH] [patch] add stubs --- filter.c | 365 ++++++++++++++++++++++++++++++++--------------------- ng.php | 4 + patch.c | 3 +- php_git2.h | 9 ++ 4 files changed, 233 insertions(+), 148 deletions(-) diff --git a/filter.c b/filter.c index c7a19b8a4c..d1f013e9f7 100644 --- a/filter.c +++ b/filter.c @@ -2,146 +2,204 @@ #include "php_git2_priv.h" #include "filter.h" -/* {{{ proto resource git_filter_list_load(repo, blob, path, mode) -*/ +/* {{{ proto long git_filter_list_load(resource $repo, resource $blob, string $path, $mode) + */ PHP_FUNCTION(git_filter_list_load) { - zval *repo; - php_git2_t *_repo; - zval *blob; - php_git2_t *_blob; - char *path = {0}; - int path_len; - zval *mode; - php_git2_t *_mode; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_load not implemented yet"); - return; + int result = 0; + git_filter_list *filters = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *blob = NULL; + php_git2_t *_blob = NULL; + char *path = NULL; + int path_len = 0; + long mode = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrsr", &repo, &blob, &path, &path_len, &mode) == FAILURE) { + "rrsl", &repo, &blob, &path, &path_len, &mode) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_blob, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_list_load(&filters, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_blob, blob), path, mode); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_filter_list_apply_to_data(filters, in) -*/ + +/* {{{ proto resource git_filter_list_apply_to_data(resource $filters, resource $in) + */ PHP_FUNCTION(git_filter_list_apply_to_data) { - zval *filters; - php_git2_t *_filters; - zval *in; - php_git2_t *_in; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_apply_to_data not implemented yet"); - return; + php_git2_t *result = NULL; + git_buf out = {0}; + zval *filters = NULL; + php_git2_t *_filters = NULL; + zval *in = NULL; + php_git2_t *_in = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &filters, &in) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_in, php_git2_t*, &in, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_filter_list_apply_to_data(&out, PHP_GIT2_V(_filters, filter_list), PHP_GIT2_V(_in, buf)); + if (php_git2_check_error(error, "git_filter_list_apply_to_data" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, buf) = &out; + result->type = PHP_GIT2_TYPE_BUF; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_filter_list_apply_to_file(filters, repo, path) -*/ + +/* {{{ proto resource git_filter_list_apply_to_file(resource $filters, resource $repo, string $path) + */ PHP_FUNCTION(git_filter_list_apply_to_file) { - zval *filters; - php_git2_t *_filters; - zval *repo; - php_git2_t *_repo; - char *path = {0}; - int path_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_apply_to_file not implemented yet"); - return; + php_git2_t *result = NULL; + git_buf out = {0}; + zval *filters = NULL; + php_git2_t *_filters = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *path = NULL; + int path_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrs", &filters, &repo, &path, &path_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_filter_list_apply_to_file(&out, PHP_GIT2_V(_filters, filter_list), PHP_GIT2_V(_repo, repository), path); + if (php_git2_check_error(error, "git_filter_list_apply_to_file" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, buf) = &out; + result->type = PHP_GIT2_TYPE_BUF; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_filter_list_apply_to_blob(filters, blob) -*/ + +/* {{{ proto resource git_filter_list_apply_to_blob(resource $filters, resource $blob) + */ PHP_FUNCTION(git_filter_list_apply_to_blob) { - zval *filters; - php_git2_t *_filters; - zval *blob; - php_git2_t *_blob; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_apply_to_blob not implemented yet"); - return; + php_git2_t *result = NULL; + git_buf out = {0}; + zval *filters = NULL; + php_git2_t *_filters = NULL; + zval *blob = NULL; + php_git2_t *_blob = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &filters, &blob) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_blob, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_filter_list_apply_to_blob(&out, PHP_GIT2_V(_filters, filter_list), PHP_GIT2_V(_blob, blob)); + if (php_git2_check_error(error, "git_filter_list_apply_to_blob" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, buf) = &out; + result->type = PHP_GIT2_TYPE_BUF; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto void git_filter_list_free(filters) -*/ + +/* {{{ proto void git_filter_list_free(resource $filters) + */ PHP_FUNCTION(git_filter_list_free) { - zval *filters; - php_git2_t *_filters; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_free not implemented yet"); - return; + zval *filters = NULL; + php_git2_t *_filters = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &filters) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_filters->should_free_v) { + git_filter_list_free(PHP_GIT2_V(_filters, filter_list)); + }; + zval_ptr_dtor(&filters); } +/* }}} */ -/* {{{ proto resource git_filter_lookup(name) -*/ +/* {{{ proto resource git_filter_lookup(string $name) + */ PHP_FUNCTION(git_filter_lookup) { - char *name = {0}; - int name_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_lookup not implemented yet"); - return; + git_filter *result = NULL; + char *name = NULL; + int name_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; } + + result = git_filter_lookup(name); + /* TODO(chobie): implement this */ } +/* }}} */ -/* {{{ proto resource git_filter_list_new(repo, mode) -*/ + +/* {{{ proto resource git_filter_list_new(resource $repo, $mode) + */ PHP_FUNCTION(git_filter_list_new) { - zval *repo; - php_git2_t *_repo; - zval *mode; - php_git2_t *_mode; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_new not implemented yet"); - return; + php_git2_t *result = NULL; + git_filter_list *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + long mode = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &repo, &mode) == FAILURE) { + "rl", &repo, &mode) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_filter_list_new(&out, PHP_GIT2_V(_repo, repository), mode); + if (php_git2_check_error(error, "git_filter_list_new" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, filter_list) = out; + result->type = PHP_GIT2_TYPE_FILTER_LIST; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ + /* {{{ proto long git_filter_list_push(fl, filter, payload) */ @@ -163,149 +221,164 @@ PHP_FUNCTION(git_filter_list_push) // ZEND_FETCH_RESOURCE(_fl, php_git2_t*, &fl, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); } -/* {{{ proto resource git_filter_list_length(fl) -*/ +/* {{{ proto long git_filter_list_length(resource $fl) + */ PHP_FUNCTION(git_filter_list_length) { - zval *fl; - php_git2_t *_fl; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_length not implemented yet"); - return; + size_t result = 0; + zval *fl = NULL; + php_git2_t *_fl = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &fl) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_fl, php_git2_t*, &fl, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_list_length(PHP_GIT2_V(_fl, filter_list)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_filter_source_repo(src) -*/ + +/* {{{ proto resource git_filter_source_repo(resource $src) + */ PHP_FUNCTION(git_filter_source_repo) { - zval *src; - php_git2_t *_src; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_repo not implemented yet"); - return; + git_repository *result = NULL; + zval *src = NULL; + php_git2_t *_src = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &src) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_repo(PHP_GIT2_V(_src, filter_source)); + /* TODO(chobie): implement this */ } +/* }}} */ -/* {{{ proto resource git_filter_source_path(src) -*/ + +/* {{{ proto string git_filter_source_path(resource $src) + */ PHP_FUNCTION(git_filter_source_path) { - zval *src; - php_git2_t *_src; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_path not implemented yet"); - return; + const char *result = NULL; + zval *src = NULL; + php_git2_t *_src = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &src) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_path(PHP_GIT2_V(_src, filter_source)); + RETURN_STRING(result, 1); } +/* }}} */ -/* {{{ proto resource git_filter_source_filemode(src) -*/ + +/* {{{ proto long git_filter_source_filemode(resource $src) + */ PHP_FUNCTION(git_filter_source_filemode) { - zval *src; - php_git2_t *_src; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_filemode not implemented yet"); - return; + uint16_t result = 0; + zval *src = NULL; + php_git2_t *_src = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &src) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_filemode(PHP_GIT2_V(_src, filter_source)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_filter_source_id(src) -*/ + +/* {{{ proto resource git_filter_source_id(resource $src) + */ PHP_FUNCTION(git_filter_source_id) { - zval *src; - php_git2_t *_src; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_id not implemented yet"); - return; + const git_oid *result = NULL; + zval *src = NULL; + php_git2_t *_src = NULL; + char __result[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &src) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_id(PHP_GIT2_V(_src, filter_source)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); } +/* }}} */ -/* {{{ proto resource git_filter_source_mode(src) -*/ + +/* {{{ proto resource git_filter_source_mode(resource $src) + */ PHP_FUNCTION(git_filter_source_mode) { - zval *src; - php_git2_t *_src; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_mode not implemented yet"); - return; + git_filter_mode_t *result = NULL; + zval *src = NULL; + php_git2_t *_src = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &src) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_mode(PHP_GIT2_V(_src, filter_source)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_filter_register(name, filter, priority) -*/ + +/* {{{ proto long git_filter_register(string $name, $filter, long $priority) + */ PHP_FUNCTION(git_filter_register) { - char *name = {0}; - int name_len; - zval *filter; - php_git2_t *_filter; - long priority; + int result = 0; + char *name = NULL; + int name_len = 0; + zval *filter = NULL; + long priority = 0; + int error = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_register not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "sal", &name, &name_len, &filter, &priority) == FAILURE) { + return; + } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "srl", &name, &name_len, &filter, &priority) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_name, php_git2_t*, &name, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_register(name, filter, priority); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_filter_unregister(name) -*/ +/* {{{ proto long git_filter_unregister(string $name) + */ PHP_FUNCTION(git_filter_unregister) { - char *name = {0}; - int name_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_unregister not implemented yet"); - return; + int result = 0; + char *name = NULL; + int name_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; } -} + result = git_filter_unregister(name); + RETURN_LONG(result); +} +/* }}} */ diff --git a/ng.php b/ng.php index fb30e928e9..a1f9072961 100644 --- a/ng.php +++ b/ng.php @@ -355,6 +355,10 @@ public function shouldResource(Arg $arg) "git_diff", "git_patch", "git_diff_hunk", + "git_filter_list", + "git_buf", + "git_filter_source", + "git_diff_line", ); } diff --git a/patch.c b/patch.c index 8726c53ab8..392975b1f8 100644 --- a/patch.c +++ b/patch.c @@ -71,7 +71,7 @@ PHP_FUNCTION(git_patch_from_blobs) } /* }}} */ -/* {{{ proto resource git_patch_from_blob_and_buffer(resource $old_blob, string $old_as_path, string $buffer, long $buffer_len, string $buffer_as_path, $opts) +/* {{{ proto resource git_patch_from_blob_and_buffer(resource $old_blob, string $old_as_path, string $buffer, string $buffer_as_path, $opts) */ PHP_FUNCTION(git_patch_from_blob_and_buffer) { @@ -83,7 +83,6 @@ PHP_FUNCTION(git_patch_from_blob_and_buffer) int old_as_path_len = 0; char *buffer = NULL; int buffer_len = 0; - long buffer_len = 0; char *buffer_as_path = NULL; int buffer_as_path_len = 0; zval *opts = NULL; diff --git a/php_git2.h b/php_git2.h index a619e5d11a..e271b32094 100644 --- a/php_git2.h +++ b/php_git2.h @@ -48,6 +48,7 @@ #include "limits.h" #include "git2.h" +#include "git2/sys/filter.h" #include "date/php_date.h" @@ -100,6 +101,10 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST, PHP_GIT2_TYPE_PATCH, PHP_GIT2_TYPE_DIFF_HUNK, + PHP_GIT2_TYPE_BUF, + PHP_GIT2_TYPE_FILTER_LIST, + PHP_GIT2_TYPE_FILTER_SOURCE, + PHP_GIT2_TYPE_DIFF_LINE, }; typedef struct php_git2_t { @@ -131,6 +136,10 @@ typedef struct php_git2_t { git_pathspec_match_list *pathspec_match_list; git_patch *patch; git_diff_hunk *diff_hunk; + git_buf *buf; + git_filter_list *filter_list; + git_filter_source *filter_source; + git_diff_line *diff_line; } v; int should_free_v; int resource_id;