PHP bindings for libgit2
C C++ PHP Other
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
libgit2 @ 43cb8b3
script
stubs
tests
.gitignore
.gitmodules
.travis.yml
LICENSE why i forgot to commit LICENSE file ? Jan 25, 2012
README.md Update README.md Mar 14, 2017
attr.c
attr.h
blame.c
blame.h [blame] implement functions Jan 17, 2014
blob.c
blob.h
branch.c
branch.h
checkout.c
checkout.h
clone.c
clone.h
commit.c
commit.h
config.m4
cred.c
cred.h
diff.c
diff.h
fe.php
filter.c
filter.h
fixer.php
g_config.c
g_config.h [diff] add diff_options interchange functions Jan 16, 2014
gen.php
giterr.c
giterr.h
graph.c
graph.h
helper.c
helper.h
ignore.c
ignore.h
index.c [update] use return_value and RETVAL_ARR instead of RETURN_ZVAL if re… Oct 26, 2016
index.h [diff] add diff_options interchange functions Jan 16, 2014
indexer.c
indexer.h
merge.c
merge.h
message.c [update] php_git2_multi_cb_init num_callbacks param Oct 20, 2016
message.h add message Jan 12, 2014
ng.php
note.c
note.h
object.c
object.h
odb.c
odb.h
packbuilder.c
packbuilder.h [packbuilder] add callbacks Jan 18, 2014
patch.c
patch.h
pathspec.c
pathspec.h
php_git2.c
php_git2.h
php_git2_priv.h
push.c [update] generate opts with init Nov 7, 2016
push.h
ref.php
reference.c
reference.h
reflog.c [update] use return_value and RETVAL_ARR instead of RETURN_ZVAL if re… Oct 26, 2016
reflog.h
refspec.c
refspec.h
remote.c [update] generate opts with init Nov 7, 2016
remote.h
repository.c [update] use value instead of pointer as declaration of libgit option… Oct 27, 2016
repository.h
reset.c [update] refactor files with gen.php Oct 4, 2016
reset.h add reset Jan 12, 2014
revparse.c
revparse.h
revwalk.c
revwalk.h
signature.c
signature.h add signature Jan 12, 2014
stash.c
stash.h
status.c
status.h
submodule.c [update] ZVAL_RESOURCE macro-calls to RETURN_RES or ZVAL_RES if not c… Oct 20, 2016
submodule.h [submodule] implement submodule functions Jan 19, 2014
tag.c [update] use return_value and RETVAL_ARR instead of RETURN_ZVAL if re… Oct 26, 2016
tag.h
transport.c
transport.h
tree.c
tree.h
treebuilder.c
treebuilder.h

README.md

PHP-Git2 - libgit2 bindings in PHP

php-git2 is a PHP bindings to the libgit2 linkable C Git library.

Requirements

PHP 7.0 above

How to build

# build libgit2.a
## For 32bit systems
git submodule init && git submodule update
mkdir libgit2/build
cd libgit2/build
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF ..
cmake --build .

# For 64bit systems
git submodule init && git submodule update
mkdir libgit2/build
cd libgit2/build
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF \
-DCMAKE_C_FLAGS=-fPIC ..
cmake --build .


# build php-git2
cd ../../
phpize
./configure --enable-git2-debug
make
make install
# add extension=git2.so to your php.ini

For Contributors

Issue first.

please make a issue first. don't work before creating it.

Coding Styles

follow pecl coding standards (except 8 at this moment).

Signature conversions
GIT_EXTERN(int) git_repository_init(
        git_repository **out,
        const char *path,
        unsigned is_bare);


// error code should handle in extension.
// resource creation or getting functions will return their resource or bool.
resource|bool function git_repository_init(string $path, long $is_bare);

public struct (e.g: git_config_entry) should consider return as an array.
file name rules.

basically, we rely libgit2 grouping at this time. (branch group functions should be in branch.c) some group (e.g config) will conflicts php header files. we choose g_ prefix for now.

check grouping here libgit2.github.com/libgit2/#v0.20.0

generating files

if you wanna try to work new file. please use gen.php and generate stubs. as declarations are bored task. (sometimes, this generator might output wrong headers. then just comment out or fix generator)

PRINT_HEADER=1 php ng.php libgit2/include/git2/branch.h > branch.h
php ng.php libgit2/include/git2/branch.h > branch.c

you can generate PHP_FE with this. past it to php_git2.c

php fe.php target.c

Note: usually, these generators might output needless variables. DON'T PR prettify codes at this moment. As we have more than 500 php functions. we like to use some fixer command than fix by hand.

documents

use prototype.

  /* {{{ proto int abs(int number)
     Returns the absolute value of the number */
  PHP_FUNCTION(abs)
  {
     ...
  }
  /* }}} */

document will generate later. please check source code before publish docs.

testing

[group]/[function].phpt

policy
  • don't create OOP interface in extension for ease of maintenance.
  • follow latest libgit2 api. don't consider BC at this time.

LICENSE

MIT License