added Git2\Walker · libgit2/php-git@70d376a · GitHub
Skip to content

Commit 70d376a

Browse files
committed
added Git2\Walker
1 parent 10a3d7e commit 70d376a

28 files changed

Lines changed: 371 additions & 1 deletion

‎config.m4‎

Lines changed: 1 addition & 0 deletions

‎git2.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern void php_git2_blob_init(TSRMLS_D);
3030
extern void php_git2_tree_init(TSRMLS_D);
3131
extern void php_git2_tree_builder_init(TSRMLS_D);
3232
extern void php_git2_signature_init(TSRMLS_D);
33+
extern void php_git2_walker_init(TSRMLS_D);
3334

3435

3536
int php_git2_call_user_function_v(zval **retval, zval *obj, char *method, unsigned int method_len, unsigned int param_count, ...)
@@ -169,6 +170,7 @@ PHP_MINIT_FUNCTION(git2)
169170
php_git2_tree_builder_init(TSRMLS_C);
170171
php_git2_tree_entry_init(TSRMLS_C);
171172
php_git2_signature_init(TSRMLS_C);
173+
php_git2_walker_init(TSRMLS_C);
172174

173175
return SUCCESS;
174176
}

‎php_git2.h‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ extern PHPAPI zend_class_entry *git2_tree_class_entry;
4949
extern PHPAPI zend_class_entry *git2_tree_builder_class_entry;
5050
extern PHPAPI zend_class_entry *git2_tree_entry_class_entry;
5151
extern PHPAPI zend_class_entry *git2_tree_signature_entry;
52+
extern PHPAPI zend_class_entry *git2_walker_entry;
5253

5354
typedef struct{
5455
zend_object zo;
@@ -80,12 +81,19 @@ typedef struct{
8081
git_treebuilder *builder;
8182
} php_git2_tree_builder;
8283

83-
8484
typedef struct{
8585
zend_object zo;
8686
git_signature *signature;
8787
} php_git2_signature;
8888

89+
typedef struct{
90+
zend_object zo;
91+
git_revwalk *walker;
92+
git_oid *current;
93+
git_repository *repository;
94+
} php_git2_walker;
95+
96+
8997
# define PHP_GIT2_GET_OBJECT(STRUCT_NAME, OBJECT) (STRUCT_NAME *) zend_object_store_get_object(OBJECT TSRMLS_CC);
9098

9199
# if ZEND_MODULE_API_NO >= 20100525
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Check for Git2\Walker::construct
3+
--SKIPIF--
4+
<?php if (!extension_loaded("git2")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$path = __DIR__ . '/mock/001-01';
8+
$repo = new Git2\Repository($path);
9+
$walker = new Git2\Walker($repo);
10+
if ($walker instanceof Git2\Walker) {
11+
echo "OK" . PHP_EOL;
12+
} else {
13+
echo "FAIL" . PHP_EOL;
14+
}
15+
--EXPECT--
16+
OK

‎tests/008-02-walker_itrate.phpt‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Check for Git2\Walker::construct
3+
--SKIPIF--
4+
<?php if (!extension_loaded("git2")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$path = __DIR__ . '/mock/008-02';
8+
$repo = new Git2\Repository($path);
9+
$walker = new Git2\Walker($repo);
10+
$walker->push("6e20138dc38f9f626107f1cd3ef0f9838c43defe");
11+
12+
foreach ($walker as $oid => $commit) {
13+
printf("oid: %s\n", $oid);
14+
printf("message: %s\n", $commit->getMessage());
15+
}
16+
--EXPECT--
17+
oid: 6e20138dc38f9f626107f1cd3ef0f9838c43defe
18+
message: added section 1 contents
19+
20+
oid: 9bb8c853c9ea27609a6bdc48b78cd26a320daf7d
21+
message: added section 1
22+
23+
oid: 7fce1026cb624448e5a8cf8752bd5e19d8f2cb1f
24+
message: modified README
25+
26+
oid: ffc6c773865c1342db9cd5df5777fc91ddeb8a4d
27+
message: initial commit

‎tests/mock/008-02/COMMIT_EDITMSG‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
added section 1 contents

‎tests/mock/008-02/HEAD‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master

‎tests/mock/008-02/config‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = false
5+
logallrefupdates = true
6+
ignorecase = true
7+
base = true

‎tests/mock/008-02/description‎

Lines changed: 1 addition & 0 deletions

‎tests/mock/008-02/index‎

104 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)