Skip to content

Fixed some bugs (see change log) #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 3 additions & 94 deletions examples/git_http_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,103 +16,12 @@
*/

require "../phpgit/git.php";
require "../phpgit/http.php";

/**
* GitHttpClone
*
* Simple example showing how to implement a Git clone over http
* by extending the GitHttpBase class. In this example it uses
* the http class http://www.phpclasses.org/browse/package/3.html
*
* In order to use it, just download the http.php file from package
* mentioned above.
*
* @category VersionControl
* @package PHP-Git
* @author C�sar D. Rodas <[email protected]>
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @link http://cesar.la/git
*/
final class GitHttpClone extends GitClone
{
private $_http;

/**
* Initialize the http module.
*
* @return nothing
*/
protected function initMod()
{
$http = & $this->_http;
$http = new http_class;

$http->timeout = 30;
$http->user_agent = "PHPGit/1.0 (http://cesar.la/projects/phpgit)";
$http->prefer_curl = 0;
}

/**
* get a remote file
*
* If it has some problem, it must return an exception,
*
* @param string $file File's URL to get
*
* @return string file contents.
*/
protected function wgetFile($file)
{
$http = & $this->_http;
$url = $this->url."/".$file;
$error = $http->GetRequestArguments($url, $arguments);
if ($error!="") {
$this->throwException($error);
}
$error = $http->Open($arguments);
if ($error!="") {
$this->throwException($error);
}
$error = $http->SendRequest($arguments);
if ($error!="") {
$this->throwException($error);
}
$error = $http->ReadReplyHeaders($headers);
if ($error!="") {
$this->throwException($error);
}
if ($http->response_status != 200) {
$http->Close();
$error = "Page not found $url";
$this->throwException($error);
}

$content = "";
while (true) {
$error = $http->ReadReplyBody($body, 1000);
if ($error!="" || strlen($body) == 0) {
if ($error!="") {
$this->throwException($error);
}
break;
}
$content .= $body;
}
if (strlen($content) != $headers['content-length']) {
$this->throwException("Mismatch size");
}
$http->Close();
return $content;
}
}

/* how to use it, cloning a remote git repo (of course my repo) */
(require "http.php") or die("Please download http.php from
http://www.phpclasses.org/browse/package/3.html");

$phplibtextcat = new GitHttpClone;
$phplibtextcat->setRepoURL("http://github.com/crodas/phplibtextcat.git");
$phplibtextcat->setRepoPath("libtextcat");
$phplibtextcat->setRepoURL("http://github.com/crodas/php-git.git");
$phplibtextcat->setRepoPath("php-git");
try {
$phplibtextcat->doClone();
} catch(Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion phpgit/gitbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ final private function _unpackCompressed($fp, $size)
{
$out = "";
do {
$cstr = fread($fp, $size>4096 ? $size : 4096);
$cstr = fread($fp, $size>131072 ? $size : 131072);
$uncompressed = gzuncompress($cstr);
if ($uncompressed === false) {

Expand Down
2 changes: 1 addition & 1 deletion phpgit/gitcheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final private function _checkoutTree($id, $prefix,&$files)
chmod($prefix.$file->name, $file->perm);
} else {
$dir = "$prefix{$file->name}/";
mkdir($dir);
@mkdir($dir);
$this->_checkoutTree($file->id, $dir, $files);
}
}
Expand Down
99 changes: 99 additions & 0 deletions phpgit/githttpclone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* GitHttpClone
*
* Simple example showing how to implement a Git clone over http
* by extending the GitHttpBase class. In this example it uses
* the http class http://www.phpclasses.org/browse/package/3.html
*
* In order to use it, just download the http.php file from package
* mentioned above.
*
* @category VersionControl
* @package PHP-Git
* @author César D. Rodas <[email protected]>
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @link http://cesar.la/git
*/
final class GitHttpClone extends GitClone
{
private $_http;

/**
* Initialize the http module.
*
* @return nothing
*/
protected function initMod()
{
$http = & $this->_http;
$http = new http_class;

$http->timeout = 30;
$http->user_agent = "PHPGit/1.0 (http://cesar.la/projects/phpgit)";
$http->prefer_curl = 0;
}

/**
* get a remote file
*
* If it has some problem, it must return an exception,
*
* @param string $file File's URL to get
*
* @return string file contents.
*/
protected function wgetFile($file)
{
$http = & $this->_http;
$url = $this->url."/".$file;
$error = $http->GetRequestArguments($url, $arguments);
if ($error!="") {
$this->throwException($error);
}
$error = $http->Open($arguments);
if ($error!="") {
$this->throwException($error);
}
$error = $http->SendRequest($arguments);
if ($error!="") {
$this->throwException($error);
}
$error = $http->ReadReplyHeaders($headers);
if ($error!="") {
$this->throwException($error);
}
if ($http->response_status != 200) {
$http->Close();
$error = "Page not found $url";
$this->throwException($error);
}

$content = "";
while (true) {
$error = $http->ReadReplyBody($body, 1000);
if ($error!="" || strlen($body) == 0) {
if ($error!="") {
$this->throwException($error);
}
break;
}
$content .= $body;
}
if (strlen($content) != $headers['content-length']) {
$this->throwException("Mismatch size");
}
$http->Close();
return $content;
}
}

/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/
?>
Loading