Skip to content

Commit 83bc908

Browse files
committed
added Git2\Commit\getMessage,getMessageEncoding and parentCount methods
1 parent 9f37fe3 commit 83bc908

4 files changed

Lines changed: 109 additions & 0 deletions

File tree

commit.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,81 @@ zend_object_value php_git2_commit_new(zend_class_entry *ce TSRMLS_DC)
4444
return retval;
4545
}
4646

47+
/*
48+
{{{ proto: Git2\Commit::getMessage()
49+
*/
50+
PHP_METHOD(git2_commit, getMessage)
51+
{
52+
char *data;
53+
php_git2_commit *m_commit;
54+
55+
m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis());
56+
57+
if (m_commit != NULL) {
58+
if (m_commit->commit == NULL) {
59+
RETURN_FALSE;
60+
}
61+
62+
RETURN_STRING(git_commit_message(m_commit->commit),1);
63+
} else {
64+
RETURN_FALSE;
65+
}
66+
}
67+
/* }}} */
68+
69+
/*
70+
{{{ proto: Git2\Commit::getMessageEncoding()
71+
*/
72+
PHP_METHOD(git2_commit, getMessageEncoding)
73+
{
74+
char *encoding;
75+
php_git2_commit *m_commit;
76+
77+
m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis());
78+
79+
if (m_commit != NULL) {
80+
if (m_commit->commit == NULL) {
81+
RETURN_FALSE;
82+
}
83+
84+
encoding = git_commit_message_encoding(m_commit->commit);
85+
if (encoding != NULL) {
86+
RETURN_STRING(encoding,1);
87+
} else {
88+
RETURN_STRING("UTF-8",1);
89+
}
90+
}
91+
RETURN_FALSE;
92+
}
93+
/* }}} */
94+
95+
96+
/*
97+
{{{ proto: Git2\Commit::parentCount()
98+
*/
99+
PHP_METHOD(git2_commit, parentCount)
100+
{
101+
unsigned int parent_count = 0;
102+
php_git2_commit *m_commit;
103+
104+
m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis());
105+
106+
if (m_commit != NULL) {
107+
if (m_commit->commit == NULL) {
108+
RETURN_FALSE;
109+
}
110+
111+
parent_count = git_commit_parentcount(m_commit->commit);
112+
RETURN_LONG(parent_count);
113+
}
114+
RETURN_FALSE;
115+
}
116+
/* }}} */
47117

48118
static zend_function_entry php_git2_commit_methods[] = {
119+
PHP_ME(git2_commit, getMessage, NULL, ZEND_ACC_PUBLIC)
120+
PHP_ME(git2_commit, getMessageEncoding, NULL, ZEND_ACC_PUBLIC)
121+
PHP_ME(git2_commit, parentCount, NULL, ZEND_ACC_PUBLIC)
49122
{NULL,NULL,NULL}
50123
};
51124

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Check for Git2\Commit::construct
3+
--SKIPIF--
4+
<?php if (!extension_loaded("git2")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$repo = new Git2\Repository(__DIR__ . "/mock/001-01");
8+
$commit = $repo->lookup("ab68c54212af15d3545c41057e3a8f2f9ff6fd0d");
9+
10+
echo $commit->parentCount();
11+
--EXPECT--
12+
0
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Check for Git2\Commit::construct
3+
--SKIPIF--
4+
<?php if (!extension_loaded("git2")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$repo = new Git2\Repository(__DIR__ . "/mock/001-01");
8+
$commit = $repo->lookup("ab68c54212af15d3545c41057e3a8f2f9ff6fd0d");
9+
10+
echo $commit->getMessage();
11+
--EXPECT--
12+
initial commit
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Check for Git2\Commit::construct
3+
--SKIPIF--
4+
<?php if (!extension_loaded("git2")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$repo = new Git2\Repository(__DIR__ . "/mock/001-01");
8+
$commit = $repo->lookup("ab68c54212af15d3545c41057e3a8f2f9ff6fd0d");
9+
10+
echo $commit->getMessageEncoding();
11+
--EXPECT--
12+
UTF-8

0 commit comments

Comments
 (0)