Skip to content

Commit fbc746f

Browse files
committed
Merge remote-tracking branch 'chobie:php-git2/master' into php-git
i apologize for broken php-git extension. as my implementation was too suck to maintain the codes. re-writed codes looks not bad than old one. there are test codes on tests directory and they are very straight forward to use new php-git API. most features has their test codes. i'll add docs when i implemented most features.
2 parents afab298 + e057413 commit fbc746f

File tree

324 files changed

+5482
-10577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

324 files changed

+5482
-10577
lines changed

.gitignore

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
*.o
22

3-
# ignore build documents.
4-
5-
docs/_build/*
6-
docs/_static/*
7-
docs/_templates/*
8-
93
# ignore temporary files
104
tmp/*
115

12-
# ignore your phpunit xml file.
13-
phpunit.xml
6+
# ignore tests
7+
tests/*.php
8+
tests/*.sh
9+
tests/*.log
10+
tests/*.diff
11+
tests/*.exp
12+
tests/*.out
1413

1514
# ignore phpized files
16-
src/Makefile.global
17-
src/acinclude.m4
18-
src/aclocal.m4
19-
src/autom4te.cache
20-
src/build
21-
src/config.*
22-
src/configure
23-
src/configure*
24-
src/install-sh
25-
src/iltmain.sh
26-
src/missing
27-
src/mkinstalldirs
28-
src/run-tests.php
29-
src/*.lo
30-
src/.deps
31-
src/.libs
32-
src/libtool
33-
src/Makefile*
34-
src/modules
35-
src/ltmain.sh
36-
src/*.la
15+
Makefile.global
16+
acinclude.m4
17+
aclocal.m4
18+
autom4te.cache
19+
build
20+
config.*
21+
configure
22+
configure*
23+
install-sh
24+
iltmain.sh
25+
missing
26+
mkinstalldirs
27+
run-tests.php
28+
*.lo
29+
.deps
30+
.libs
31+
libtool
32+
Makefile*
33+
modules
34+
ltmain.sh
35+
*.la
36+
tmp-php.ini
37+
php_test_results*

CREDITS

Lines changed: 0 additions & 2 deletions
This file was deleted.

EXPERIMENTAL

Lines changed: 0 additions & 5 deletions
This file was deleted.

LIBGIT2_VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 109 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,109 @@
1-
php-git
2-
=======================================================
3-
4-
php-git is a set of PHP 5.3+ bindings to the libgit2 linkable C Git library.
5-
6-
How Can I Contribute?
7-
=======================================================
8-
9-
* fork our repository.
10-
11-
<https://github.com/libgit2/php-git>
12-
13-
* create topic branch on your repository (contributors looking issue
14-
themselves)
15-
16-
e.g. fix-repository-xxxx-bug, fix-barerepository-detection-bug.
17-
18-
topic branch desirable minimum change.
19-
20-
or post probrem to Github issues feature.
21-
https://github.com/libgit2/php-git/issues
22-
23-
then i'll fix as possible.
24-
25-
* send a pull request to me. i'll check and response in a few days.
26-
27-
28-
Current Development Status
29-
=======================================================
30-
31-
*first Alpha development*.
32-
(development started at 2010-12-30)
33-
34-
*notice* do not use this extenstion on any production server. this extension not fully tested.
35-
36-
*1st alpha development release: (2011/1/17)
37-
just work on php. not fully tested. classes and methods may changed.
38-
39-
*2nd alpha development release: (2011/2)
40-
added some unit test. libgit2 feature fully support.
41-
(i'm busy my work, 1 or 2 week delayed)
42-
43-
i'll follow libgit2 changes as possible as :)
44-
45-
DEPENDENCIES
46-
=======================================================
47-
48-
* libgit2
49-
* php5
50-
* pcre
51-
52-
INSTALL
53-
=======================================================
54-
55-
see php-git Wiki: <https://github.com/chobie/php-git/wiki>
56-
57-
58-
Documents
59-
=======================================================
60-
61-
see php-git Documents: <http://php-git.chobie.co/>
62-
63-
you can build with sphinx.
64-
65-
cd docs
66-
make html
67-
68-
AUTHORS
69-
=======================================================
70-
71-
* Shuhei Tanuma <chobieee@gmail.com>
72-
73-
LICENSE
74-
=======================================================
75-
76-
MIT Licence.
77-
78-
79-
Links
80-
=======================================================
81-
82-
* libgit2: <https://github.com/libgit2/libgit2>
83-
* php-git documents: <http://php-git.chobie.co>
1+
# PHP-Git2 - libgit2 bindings in PHP
2+
3+
php-git2 is a PHP bindings to the libgit2 linkable C Git library.
4+
this extension are re-writing php-git as that code too dirty.
5+
6+
# Installing And Running
7+
8+
````
9+
git clone https://github.com/chobie/php-git2.git
10+
cd php-git2
11+
phpize
12+
./configure
13+
make
14+
sudo make Install
15+
````
16+
17+
# API
18+
19+
## Repository Access
20+
21+
````php
22+
$repo = new Git2\Repository($path);
23+
/*
24+
bool = $repo->isExist(string sha1)
25+
Git2\Object = $repo->read(string sha1)
26+
string sha1 = $repo->hash(string content, long type)
27+
string sha1 = $repo->write(string content, long type)
28+
bool = $repo->isBare()
29+
bool = $repo->isEmpty()
30+
bool = $repo->headDetached()
31+
bool = $repo->headOrphan()
32+
string path = Git2\Repository::discover("/Users/chobie/projects/work/repo/lib/subdir");
33+
// => /Users/chobie/projects/work/repo/.git
34+
35+
Git2\Repository = Git2\Repository::init(string $path, bool isBare)
36+
*/
37+
````
38+
39+
## Object Access
40+
41+
## Tree Access
42+
43+
````
44+
$repo = new Git2\Repository($path);
45+
$tree = $repo->lookup(tree sha); // specify tree sha
46+
47+
foreach ($tree as $oid => $entry) {
48+
var_dump($entry);
49+
}
50+
````
51+
52+
## Ref Management
53+
54+
````
55+
$ref = Git2\Reference::lookup($repo, "refs/heads/master");
56+
sha = $ref->getTarget();
57+
str = $ref->getName();
58+
````
59+
60+
````
61+
foreach (Git2\Reference::each($repo) as $ref) {
62+
echo $ref->getName() . PHP_EOL;
63+
}
64+
````
65+
66+
67+
## Commit
68+
69+
````
70+
<?php
71+
date_default_timezone_set('Asia/Tokyo');
72+
$repo = Git2\Repository::init("/path/to/repo",true);
73+
74+
$author = new Git2\Signature("Shuhei Tanuma","chobieee@gmail.com",new DateTime());
75+
76+
$bld = new Git2\TreeBuilder();
77+
$bld->insert(new Git2\TreeEntry(array(
78+
"name" => "README.txt",
79+
"oid" => "63542fbea05732b78711479a31557bd1b0aa2116",
80+
"attributes" => octdec('100644'),
81+
)));
82+
$tree = $bld->write($repo);
83+
84+
$parent = "";
85+
$parents = array();
86+
for ($i = 0; $i< 10;$i++){
87+
$parent = Git2\Commit::create($repo, array(
88+
"author" => $author,
89+
"committer" => $author,
90+
"message" => "Hello World: {$i}",
91+
"tree" => $tree,
92+
"parents" => $parents,
93+
));
94+
$parents = array($parent);
95+
}
96+
````
97+
98+
## Revision Walking
99+
100+
````
101+
$repo = new Git2\Repository($path);
102+
$walker = new Git2\Walker($repo);
103+
/* specify HEAD oid */
104+
$walker->push("6e20138dc38f9f626107f1cd3ef0f9838c43defe");
105+
106+
foreach ($walker as $oid => $commit) {
107+
printf("oid: %s\n", $oid);
108+
printf("message: %s\n", $commit->getMessage());
109+
}

blob.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010 - 2012 Shuhei Tanuma
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#include "php_git2.h"
26+
27+
PHPAPI zend_class_entry *git2_blob_class_entry;
28+
29+
static void php_git2_blob_free_storage(php_git2_blob *object TSRMLS_DC)
30+
{
31+
if (object->blob != NULL) {
32+
git_blob_free(object->blob);
33+
object->blob = NULL;
34+
}
35+
zend_object_std_dtor(&object->zo TSRMLS_CC);
36+
efree(object);
37+
}
38+
39+
zend_object_value php_git2_blob_new(zend_class_entry *ce TSRMLS_DC)
40+
{
41+
zend_object_value retval;
42+
43+
PHP_GIT2_STD_CREATE_OBJECT(php_git2_blob);
44+
return retval;
45+
}
46+
47+
48+
/*
49+
{{{ proto: Git2\Blob::__toString()
50+
*/
51+
PHP_METHOD(git2_blob, __toString)
52+
{
53+
char *data;
54+
php_git2_blob *m_blob;
55+
56+
m_blob = PHP_GIT2_GET_OBJECT(php_git2_blob, getThis());
57+
58+
if (m_blob != NULL) {
59+
if (m_blob->blob == NULL) {
60+
RETURN_FALSE;
61+
}
62+
63+
RETURN_STRINGL(git_blob_rawcontent(m_blob->blob), git_blob_rawsize(m_blob->blob),1);
64+
} else {
65+
RETURN_FALSE;
66+
}
67+
}
68+
/* }}} */
69+
70+
71+
static zend_function_entry php_git2_blob_methods[] = {
72+
PHP_ME(git2_blob, __toString, NULL, ZEND_ACC_PUBLIC)
73+
{NULL,NULL,NULL}
74+
};
75+
76+
void php_git2_blob_init(TSRMLS_D)
77+
{
78+
zend_class_entry ce;
79+
80+
INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Blob", php_git2_blob_methods);
81+
git2_blob_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
82+
git2_blob_class_entry->create_object = php_git2_blob_new;
83+
}

0 commit comments

Comments
 (0)