Skip to content
Browse files

add Git2\Tree::getEntryByName(string $path)

  • Loading branch information...
1 parent 4a599ab commit 4a95e5f04f71a2729c351c98adb930cae406c604 @chobie chobie committed Feb 28, 2012
Showing with 54 additions and 0 deletions.
  1. +20 −0 tests/003-04-tree_get_entry_by_name.phpt
  2. +34 −0 tree.c
View
20 tests/003-04-tree_get_entry_by_name.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Check for Git2\Tree::construct
+--SKIPIF--
+<?php if (!extension_loaded("git2")) print "skip"; ?>
+--FILE--
+<?php
+$repo = new Git2\Repository(__DIR__ . "/mock/001-01");
+$tree = $repo->lookup("67dc4302383b2715f4e0b8c41840eb05b1873697");
+
+$entry = $tree->getEntryByName("README");
+var_dump($entry);
+--EXPECT--
+object(Git2\TreeEntry)#5 (3) {
+ ["name"]=>
+ string(6) "README"
+ ["oid"]=>
+ string(39) "557db03de997c86a4a028e1ebd3a1ceb225be23"
+ ["attributes"]=>
+ int(33188)
+}
View
34 tree.c
@@ -56,6 +56,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_tree_get_subtree, 0,0,1)
ZEND_ARG_INFO(0, path)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_tree_get_entry_by_name, 0,0,1)
+ ZEND_ARG_INFO(0, path)
+ZEND_END_ARG_INFO()
+
static int php_git2_tree_diff_cb(const git_tree_diff_data *ptr, void *data)
{
@@ -296,6 +300,35 @@ PHP_METHOD(git2_tree, getSubtree)
/* }}} */
+/*
+{{{ proto: Git2\Tree Git2\Tree::getEntryByName($name)
+*/
+PHP_METHOD(git2_tree, getEntryByName)
+{
+ char *path = NULL;
+ int path_len = 0;
+ php_git2_tree *object;
+ const git_tree_entry *entry = NULL;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
+ "s", &path, &path_len) == FAILURE) {
+ return;
+ }
+
+ object = PHP_GIT2_GET_OBJECT(php_git2_tree, getThis());
+
+ entry = git_tree_entry_byname(object->tree, (const char *)path);
+ if (entry) {
+ zval *result;
+
+ create_tree_entry_from_entry(&result, (git_tree_entry *)entry ,git_object_owner((git_object *)object->tree));
+ RETVAL_ZVAL(result, 0, 1);
+ } else {
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
static zend_function_entry php_git2_tree_methods[] = {
PHP_ME(git2_tree, diff, arginfo_git2_tree_diff, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
@@ -306,6 +339,7 @@ static zend_function_entry php_git2_tree_methods[] = {
PHP_ME(git2_tree, rewind, NULL, ZEND_ACC_PUBLIC)
PHP_ME(git2_tree, valid, NULL, ZEND_ACC_PUBLIC)
PHP_ME(git2_tree, getSubtree, arginfo_git2_tree_get_subtree, ZEND_ACC_PUBLIC)
+ PHP_ME(git2_tree, getEntryByName,arginfo_git2_tree_get_entry_by_name, ZEND_ACC_PUBLIC)
{NULL,NULL,NULL}
};

0 comments on commit 4a95e5f

Please sign in to comment.
Something went wrong with that request. Please try again.