Permalink
Browse files

[filter] add callbacks

  • Loading branch information...
chobie committed Jan 19, 2014
1 parent 4ef6d03 commit b79c3018a78226cf6cd5ec46300090be451120d4
Showing with 440 additions and 58 deletions.
  1. +19 −0 README.md
  2. +46 −0 example/filter.php
  3. +287 −25 filter.c
  4. +9 −1 filter.h
  5. +22 −1 helper.c
  6. +4 −0 helper.h
  7. +15 −0 php_git2.c
  8. +38 −0 php_git2.h
  9. +0 −31 php_git2_priv.h
View
@@ -8,6 +8,25 @@ php-git2 is a PHP bindings to the libgit2 linkable C Git library.
https://docs.google.com/spreadsheet/ccc?key=0AjvShWAWqvfHdDRneEtIUF9GRUZMNVVVR1hpdURiUWc&usp=sharing
## How to build
```
# build libgit2.a
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 .
# build php-git2
cd ../../
phpize
./configure --enable-git2-debug
make
make install
# add extension=git2.so to your php.ini
```
## For Contributors
##### Issue first.
View
@@ -0,0 +1,46 @@
<?php
$repo = git_repository_open(".");
$a = array(
// attributes are white space separated string.
// e.g) .gitattribute
// *.php filter=chobie
//
// will return $attr[0] = false, $attr[1] = "chobie" with *.php files. see check callback.
"attributes" => "chobie filter",
"initialize" => function () {
echo "\e[32m# Initialize\e[m\n";
},
"check" => function ($payload, $src, $attr) {
echo "\e[32m# Check\e[m\n";
var_dump($src);
var_dump($attr);
// return true means apply filter to this file.
return true;
},
"apply" => function ($payload, $from, $src) {
echo "\e[32m# Apply\e[m\n";
// apply function should return string or GIT_PASSTHROUGH
return preg_replace("/\s/", "", $from);
},
"shutdown" => function () {
echo "\n\e[32m# Shutdown\e[m\n";
},
"cleanup" => function () {
echo "\e[32m# clean up\e[m\n";
}
);
$v = git_filter_new($a);
git_filter_register("chobie", $v, 100);
$blob = git_blob_lookup($repo, "74f5770df516cbbef16372a7628a9528277637d6");
$l = git_filter_list_load($repo, $blob, "example/diff.php", GIT_FILTER_SMUDGE);
echo "\e[32m# <<< ORIGINAL CONTENT >>>\e[m\n";
echo git_blob_rawcontent($blob);
echo "\e[32m# <<< FILTERED CONTENT >>>\e[m\n";
$out = git_filter_list_apply_to_blob($l, $blob);
echo $out;
Oops, something went wrong.

0 comments on commit b79c301

Please sign in to comment.