Unpacking working

master
Sven Slootweg 12 years ago
parent 5db6b084c2
commit abcc1e1f6c

@ -46,10 +46,12 @@ class GitPack
case OBJ_TAG:
// this is a compressed object
$data = fread($file, $size);
return $this->repo->CreateObject(gzuncompress($data), $type, $size);
break;
case OBJ_OFS_DELTA:
case OBJ_REF_DELTA:
// this is a delta
throw new Exception("This is not yet implemented.");
break;
default:
throw new GitUnknownTypeException("The object type is not supported.");

@ -20,7 +20,36 @@ class GitRepository
function GetObject($sha)
{
list($header, $data) = explode("\0", $this->GetObjectRaw($sha), 2);
return $this->CreateObject($this->GetObjectRaw($sha));
}
function CreateObject($data, $type = null, $size = null)
{
if($type == null && $size == null)
{
list($header, $data) = explode("\0", $data, 2);
}
else
{
switch($type)
{
case OBJ_BLOB:
$typestring = "blob";
break;
case OBJ_TREE:
$typestring = "tree";
break;
case OBJ_TAG:
$typestring = "tag";
break;
case OBJ_COMMIT:
$typestring = "commit";
break;
default:
throw new GitUnknownTypeException("The specified type is not valid for this function.");
}
$header = "{$typestring} {$size}";
}
if(strpos($header, " ") !== false)
{

@ -2,5 +2,6 @@
require("libgit/base.php");
$repo = new GitRepository("/home/occupy/testrepo.git");
pretty_dump(new GitPack($repo, "pack-8503a2b8cf6e60831dd012afd4d486eb1eddfef8"));
$pack = new GitPack($repo, "pack-8503a2b8cf6e60831dd012afd4d486eb1eddfef8");
pretty_dump($pack->UnpackObject("a6269a2ffd269289d7d026818511fab88718feff"));
//pretty_dump($repo->GetObjectForPath($repo->GetBranch("master")->GetTree(), "public_html/css/images/derp"));

Loading…
Cancel
Save