|  | 
| 1 | 1 | # PHP-Git2 - libgit2 bindings in PHP | 
| 2 | 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. | 
|  | 3 | +php-git2 is a PHP bindings to the libgit2 linkable C Git library.  | 
| 5 | 4 | 
 | 
| 6 |  | -# Latest Branch | 
|  | 5 | +* API Documentation: http://libgit2.github.com/libgit2/#v0.20.0 (also see Signature conversions section) | 
|  | 6 | +* IRC: #php-git on irc.freenode.net. | 
| 7 | 7 | 
 | 
| 8 |  | -v0.3.0 (switching to functions) | 
| 9 |  | -https://github.com/libgit2/php-git/tree/functions | 
|  | 8 | +## Status | 
| 10 | 9 | 
 | 
| 11 |  | -# Important Notice | 
|  | 10 | +0.3.0 Alpha (switching to functions) | 
| 12 | 11 | 
 | 
| 13 |  | -php-git changed it's API drastically. this changes doesn't care about compatibility between old one. | 
| 14 |  | -please check tests cases. | 
|  | 12 | +https://docs.google.com/spreadsheet/ccc?key=0AjvShWAWqvfHdDRneEtIUF9GRUZMNVVVR1hpdURiUWc&usp=sharing | 
| 15 | 13 | 
 | 
| 16 |  | -# Installing And Running | 
|  | 14 | +## How to build | 
| 17 | 15 | 
 | 
| 18 |  | -you need to install libgit2 before make php-git. | 
|  | 16 | +``` | 
|  | 17 | +# build libgit2.a | 
|  | 18 | +git submodule init && git submodule update | 
|  | 19 | +mkdir libgit2/build | 
|  | 20 | +cd libgit2/build | 
|  | 21 | +cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF .. | 
|  | 22 | +cmake --build . | 
| 19 | 23 | 
 | 
| 20 |  | -```` | 
| 21 |  | -git clone https://github.com/libgit2/php-git.git --recursive | 
| 22 |  | -cd php-git/libgit2 | 
| 23 |  | -mkdir build && cd build | 
| 24 |  | -cmake .. | 
| 25 |  | -cmake -DBUILD_SHARED_LIBS=OFF -build . | 
| 26 |  | -make | 
|  | 24 | +# build php-git2 | 
| 27 | 25 | cd ../../ | 
| 28 | 26 | phpize | 
| 29 |  | -./configure | 
|  | 27 | +./configure --enable-git2-debug | 
| 30 | 28 | make | 
| 31 | 29 | make install | 
| 32 |  | -sudo make install | 
| 33 |  | -# add `extension=git2.so` to your php.ini | 
| 34 |  | -```` | 
|  | 30 | +# add extension=git2.so to your php.ini | 
|  | 31 | +``` | 
| 35 | 32 | 
 | 
| 36 |  | -new php-git features almost tested. | 
|  | 33 | +## For Contributors | 
| 37 | 34 | 
 | 
| 38 |  | -# API | 
|  | 35 | +##### Issue first. | 
| 39 | 36 | 
 | 
| 40 |  | -## Repository Access | 
|  | 37 | +please make a issue first. don't work before creating it. | 
| 41 | 38 | 
 | 
| 42 |  | -````php | 
| 43 |  | -$repo = new Git2\Repository($path); | 
| 44 |  | -/* | 
| 45 |  | -  bool = $repo->exists(string sha1) | 
| 46 |  | -  Git2\Object = $repo->lookup(string sha1) | 
| 47 |  | -  string sha1 = $repo->hash(string content, long type) | 
| 48 |  | -  string sha1 = $repo->write(string content, long type) | 
| 49 |  | -  bool = $repo->isBare() | 
| 50 |  | -  bool = $repo->isEmpty() | 
| 51 |  | -  bool = $repo->headDetached() | 
| 52 |  | -  bool = $repo->headOrphan() | 
| 53 |  | -  string path = Git2\Repository::discover("/Users/chobie/projects/work/repo/lib/subdir"); | 
| 54 |  | -  // => /Users/chobie/projects/work/repo/.git | 
|  | 39 | +##### Coding Styles | 
| 55 | 40 | 
 | 
| 56 |  | -  Git2\Repository = Git2\Repository::init(string $path, bool isBare) | 
| 57 |  | -*/ | 
| 58 |  | -```` | 
|  | 41 | +follow pecl coding standards (except 8 at this moment). | 
| 59 | 42 | 
 | 
| 60 |  | -## Object Access | 
|  | 43 | +* http://git.php.net/?p=php-src.git;a=blob_plain;f=CODING_STANDARDS;hb=HEAD | 
| 61 | 44 | 
 | 
| 62 |  | -### create new blob | 
|  | 45 | +##### Signature conversions | 
| 63 | 46 | 
 | 
| 64 | 47 | ```` | 
| 65 |  | -$oid = Git2\Blob::create($repo, "Hello World"); | 
| 66 |  | -/* | 
| 67 |  | -  $blob = $repo->lookup($oid); | 
| 68 |  | -  int $blob->getSize(); | 
| 69 |  | -  string $blob->getContent(); | 
| 70 |  | -*/ | 
| 71 |  | -```` | 
|  | 48 | +GIT_EXTERN(int) git_repository_init( | 
|  | 49 | +        git_repository **out, | 
|  | 50 | +        const char *path, | 
|  | 51 | +        unsigned is_bare); | 
| 72 | 52 | 
 | 
| 73 |  | -## Tree Access | 
| 74 | 53 | 
 | 
| 75 |  | -```` | 
| 76 |  | -$repo = new Git2\Repository($path); | 
| 77 |  | -$tree = $repo->lookup(tree sha); // specify tree sha | 
| 78 |  | -foreach ($tree as $oid => $entry) { | 
| 79 |  | -/* | 
| 80 |  | -  bool $entry->isTree(); | 
| 81 |  | -  bool $entry->isBlob(); | 
| 82 |  | -  bool $entry->isSubmodule(); | 
| 83 |  | -*/ | 
| 84 |  | -        var_dump($entry); | 
| 85 |  | -} | 
| 86 |  | -```` | 
|  | 54 | +// error code should handle in extension. | 
|  | 55 | +// resource creation or getting functions will return their resource or bool. | 
|  | 56 | +resource|bool function git_repository_init(string $path, long $is_bare); | 
| 87 | 57 | 
 | 
| 88 |  | -## Ref Management | 
| 89 |  | - | 
| 90 |  | -```` | 
| 91 |  | -$ref = Git2\Reference::lookup($repo, "refs/heads/master"); | 
| 92 |  | -  sha = $ref->getTarget(); | 
| 93 |  | -  str = $ref->getName(); | 
|  | 58 | +public struct (e.g: git_config_entry) should consider return as an array. | 
| 94 | 59 | ```` | 
| 95 | 60 | 
 | 
| 96 |  | -```` | 
| 97 |  | -foreach (Git2\Reference::each($repo) as $ref) { | 
| 98 |  | -  echo $ref->getName() . PHP_EOL; | 
| 99 |  | -} | 
| 100 |  | -```` | 
|  | 61 | +##### file name rules. | 
| 101 | 62 | 
 | 
|  | 63 | +basically, we rely libgit2 grouping at this time. (`branch` group functions should be in branch.c) | 
|  | 64 | +some group (e.g config) will conflicts php header files. we choose `g_` prefix for now. | 
| 102 | 65 | 
 | 
| 103 |  | -## Commit | 
|  | 66 | +check grouping here libgit2.github.com/libgit2/#v0.20.0 | 
| 104 | 67 | 
 | 
| 105 |  | -```` | 
| 106 |  | -<?php | 
| 107 |  | -date_default_timezone_set('Asia/Tokyo'); | 
| 108 |  | -$repo = Git2\Repository::init("/path/to/repo",true); | 
| 109 |  | -
 | 
| 110 |  | -$author = new Git2\Signature("Shuhei Tanuma","[email protected]",new DateTime()); | 
| 111 |  | -
 | 
| 112 |  | -$bld = new Git2\TreeBuilder(); | 
| 113 |  | -$bld->insert(new Git2\TreeEntry(array( | 
| 114 |  | -	"name" => "README.txt", | 
| 115 |  | -	"oid" => "63542fbea05732b78711479a31557bd1b0aa2116", | 
| 116 |  | -	"attributes" => octdec('100644'), | 
| 117 |  | -))); | 
| 118 |  | -$tree = $bld->write($repo); | 
| 119 |  | -
 | 
| 120 |  | -$parent = ""; | 
| 121 |  | -$parents = array(); | 
| 122 |  | -$parent = Git2\Commit::create($repo, array( | 
| 123 |  | -	"author"    => $author, | 
| 124 |  | -	"committer" => $author, | 
| 125 |  | -	"message"   => "Hello World", | 
| 126 |  | -	"tree"      => $tree, | 
| 127 |  | -	"parents"   => $parents, | 
| 128 |  | -)); | 
| 129 |  | -```` | 
|  | 68 | +##### generating files | 
| 130 | 69 | 
 | 
| 131 |  | -## Revision Walking | 
|  | 70 | +if you wanna try to work new file. please use gen.php and generate stubs. as declarations are bored task. | 
|  | 71 | +(sometimes, this generator might output wrong headers. then just comment out or fix generator) | 
| 132 | 72 | 
 | 
| 133 | 73 | ```` | 
| 134 |  | -$repo = new Git2\Repository($path); | 
| 135 |  | -$walker = new Git2\Walker($repo); | 
| 136 |  | -/* specify HEAD oid */ | 
| 137 |  | -$walker->push("6e20138dc38f9f626107f1cd3ef0f9838c43defe"); | 
| 138 |  | -
 | 
| 139 |  | -foreach ($walker as $oid => $commit) { | 
| 140 |  | -        printf("oid: %s\n", $oid); | 
| 141 |  | -        printf("message: %s\n", $commit->getMessage()); | 
| 142 |  | -} | 
|  | 74 | +PRINT_HEADER=1 php ng.php libgit2/include/git2/branch.h > branch.h | 
|  | 75 | +php ng.php libgit2/include/git2/branch.h > branch.c | 
| 143 | 76 | ```` | 
| 144 | 77 | 
 | 
| 145 |  | -## Config access | 
|  | 78 | +you can generate `PHP_FE` with this. past it to `php_git2.c` | 
| 146 | 79 | 
 | 
| 147 | 80 | ```` | 
| 148 |  | -$config = new Git2\Config("path/to/git/config"); | 
| 149 |  | -$config->get("core.bare"); | 
| 150 |  | -$config->store("core.bare","1"); | 
| 151 |  | -
 | 
| 152 |  | -// Git2\Config supports read / write dimension. | 
| 153 |  | -$config['core.bare'] | 
| 154 |  | -$config['core.bare'] = 1; | 
|  | 81 | +php fe.php target.c | 
| 155 | 82 | ```` | 
| 156 | 83 | 
 | 
| 157 |  | -## ODB operation | 
|  | 84 | +Note: usually, these generators might output needless variables. DON'T PR `prettify codes` at this moment. | 
|  | 85 | +As we have more than 500 php functions. we like to use some fixer command than fix by hand. | 
| 158 | 86 | 
 | 
| 159 |  | -```` | 
| 160 |  | -$repo = Git2\Repository::init("/path/to/repo",true); | 
| 161 |  | -$odb = $repo->odb // read only property | 
| 162 |  | -Git\OdbObject $odb->read(sha1) // returns uncompressed git raw data. | 
| 163 |  | -string $odb->hash(string contents, int type)// same as Git2\Repository::hash | 
| 164 |  | -string $odb->write(string contents, int type)// same as Git2\Repository::write | 
| 165 |  | -bool $odb->exists(sha1)// same as Git2\Repository::exists | 
| 166 |  | -```` | 
|  | 87 | +##### documents | 
| 167 | 88 | 
 | 
| 168 |  | -## Reflog | 
| 169 |  | -will be add. | 
|  | 89 | +use prototype. | 
| 170 | 90 | 
 | 
| 171 |  | -## Remote access (Experimental) | 
|  | 91 | +``` | 
|  | 92 | +  /* {{{ proto int abs(int number) | 
|  | 93 | +     Returns the absolute value of the number */ | 
|  | 94 | +  PHP_FUNCTION(abs) | 
|  | 95 | +  { | 
|  | 96 | +     ... | 
|  | 97 | +  } | 
|  | 98 | +  /* }}} */ | 
|  | 99 | +``` | 
| 172 | 100 | 
 | 
| 173 |  | -this API will be change. | 
|  | 101 | +document will generate later. please check source code before publish docs. | 
| 174 | 102 | 
 | 
| 175 |  | -```` | 
| 176 |  | -$repo = new Git2\Repository("/path/to/.git"); | 
| 177 |  | -$remote = new Git2\Remote($repo,"http://github.com/libgit2/php-git.git"); | 
| 178 |  | -// for now, remote can fetch files only. that does not update references. | 
| 179 |  | -$remote->fetch(); | 
| 180 |  | -```` | 
|  | 103 | +##### testing | 
| 181 | 104 | 
 | 
| 182 |  | -## Author | 
| 183 |  | -* Shuhei Tanuma | 
|  | 105 | +[group]/[function].phpt | 
| 184 | 106 | 
 | 
| 185 |  | -## Contributors | 
|  | 107 | +##### policy | 
| 186 | 108 | 
 | 
| 187 |  | -* Anthony Van de Gejuchte | 
| 188 |  | -* Cameron Eagans | 
| 189 |  | -* Graham Weldon | 
| 190 |  | -* James Titcumb | 
| 191 |  | -* Matthieu Moquet | 
| 192 |  | -* Ryusuke SEKIYAMA | 
| 193 |  | -* Shuhei Tanuma | 
| 194 |  | -* Vasileios Georgitzikis | 
| 195 |  | -* tsteiner | 
|  | 109 | +* don't create OOP interface in extension for ease of maintenance. | 
|  | 110 | +* follow latest libgit2 api. don't consider BC at this time. | 
| 196 | 111 | 
 | 
| 197 | 112 | ## LICENSE | 
| 198 | 113 | 
 | 
| 199 |  | -MIT License | 
|  | 114 | +MIT License | 
0 commit comments