Skip to content

Commit b79c301

Browse files
committedJan 19, 2014
[filter] add callbacks
1 parent 4ef6d03 commit b79c301

9 files changed

+440
-58
lines changed
 

‎README.md

+19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ php-git2 is a PHP bindings to the libgit2 linkable C Git library.
88

99
https://docs.google.com/spreadsheet/ccc?key=0AjvShWAWqvfHdDRneEtIUF9GRUZMNVVVR1hpdURiUWc&usp=sharing
1010

11+
## How to build
12+
13+
```
14+
# build libgit2.a
15+
git submodule init && git submodule update
16+
mkdir libgit2/build
17+
cd libgit2/build
18+
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF .
19+
cmake --build .
20+
21+
# build php-git2
22+
cd ../../
23+
phpize
24+
./configure --enable-git2-debug
25+
make
26+
make install
27+
# add extension=git2.so to your php.ini
28+
```
29+
1130
## For Contributors
1231

1332
##### Issue first.

‎example/filter.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
$repo = git_repository_open(".");
3+
4+
$a = array(
5+
// attributes are white space separated string.
6+
// e.g) .gitattribute
7+
// *.php filter=chobie
8+
//
9+
// will return $attr[0] = false, $attr[1] = "chobie" with *.php files. see check callback.
10+
"attributes" => "chobie filter",
11+
"initialize" => function () {
12+
echo "\e[32m# Initialize\e[m\n";
13+
},
14+
"check" => function ($payload, $src, $attr) {
15+
echo "\e[32m# Check\e[m\n";
16+
var_dump($src);
17+
var_dump($attr);
18+
19+
// return true means apply filter to this file.
20+
return true;
21+
},
22+
"apply" => function ($payload, $from, $src) {
23+
echo "\e[32m# Apply\e[m\n";
24+
// apply function should return string or GIT_PASSTHROUGH
25+
return preg_replace("/\s/", "", $from);
26+
},
27+
"shutdown" => function () {
28+
echo "\n\e[32m# Shutdown\e[m\n";
29+
},
30+
"cleanup" => function () {
31+
echo "\e[32m# clean up\e[m\n";
32+
}
33+
);
34+
35+
$v = git_filter_new($a);
36+
git_filter_register("chobie", $v, 100);
37+
38+
$blob = git_blob_lookup($repo, "74f5770df516cbbef16372a7628a9528277637d6");
39+
$l = git_filter_list_load($repo, $blob, "example/diff.php", GIT_FILTER_SMUDGE);
40+
41+
echo "\e[32m# <<< ORIGINAL CONTENT >>>\e[m\n";
42+
echo git_blob_rawcontent($blob);
43+
44+
echo "\e[32m# <<< FILTERED CONTENT >>>\e[m\n";
45+
$out = git_filter_list_apply_to_blob($l, $blob);
46+
echo $out;

0 commit comments

Comments
 (0)
Please sign in to comment.