2012-05-05 20:06:53 +02:00
|
|
|
<?php
|
|
|
|
class GitRepository
|
|
|
|
{
|
|
|
|
public $path = "";
|
|
|
|
|
|
|
|
function __construct($path)
|
|
|
|
{
|
|
|
|
$this->path = $path;
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetObjectRaw($sha)
|
|
|
|
{
|
|
|
|
return gzuncompress(
|
|
|
|
file_get_contents(
|
|
|
|
sprintf("{$this->path}/objects/%s/%s",
|
|
|
|
substr($sha, 0, 2),
|
|
|
|
substr($sha, 2)
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetObject($sha)
|
|
|
|
{
|
|
|
|
list($header, $data) = explode("\0", $this->GetObjectRaw($sha), 2);
|
|
|
|
|
|
|
|
if(strpos($header, " ") !== false)
|
|
|
|
{
|
|
|
|
list($type, $headerdata) = explode(" ", $header, 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$type = $header;
|
|
|
|
$headerdata = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
switch($type)
|
|
|
|
{
|
|
|
|
case "commit":
|
2012-05-05 20:21:21 +02:00
|
|
|
return new GitCommit($this, $headerdata, $data);
|
2012-05-05 20:06:53 +02:00
|
|
|
break;
|
|
|
|
case "blob":
|
2012-05-05 20:21:21 +02:00
|
|
|
return new GitBlob($this, $headerdata, $data);
|
2012-05-05 20:06:53 +02:00
|
|
|
break;
|
|
|
|
case "tree":
|
2012-05-05 20:21:21 +02:00
|
|
|
return new GitTree($this, $headerdata, $data);
|
2012-05-05 20:06:53 +02:00
|
|
|
break;
|
|
|
|
case "tag":
|
2012-05-05 20:21:21 +02:00
|
|
|
return new GitTag($this, $headerdata, $data);
|
2012-05-05 20:06:53 +02:00
|
|
|
break;
|
|
|
|
default:
|
2012-05-05 20:21:21 +02:00
|
|
|
return new GitObject($this, $headerdata, $data);
|
2012-05-05 20:06:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-05-05 21:40:16 +02:00
|
|
|
|
|
|
|
function GetBranch($name)
|
|
|
|
{
|
2012-05-05 22:19:35 +02:00
|
|
|
$filename = "{$this->path}/refs/heads/{$name}";
|
|
|
|
|
|
|
|
if(file_exists($filename))
|
|
|
|
{
|
|
|
|
$sha = trim(file_get_contents($filename));
|
|
|
|
return new GitBranch($this, $sha);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new GitBranchNotFoundException("The {$name} branch does not exist.");
|
|
|
|
}
|
2012-05-05 21:40:16 +02:00
|
|
|
}
|
2012-05-05 20:06:53 +02:00
|
|
|
}
|