diff --git a/public_html/libgit/class.blob.php b/public_html/libgit/class.blob.php
index 37cc44a..9d4578c 100644
--- a/public_html/libgit/class.blob.php
+++ b/public_html/libgit/class.blob.php
@@ -1,8 +1,8 @@
repo = $repo;
$this->size = (int)$headerdata;
$this->rawdata = $data;
+ $this->sha = $sha;
}
}
diff --git a/public_html/libgit/class.pack.php b/public_html/libgit/class.pack.php
index d4612a6..a45bc95 100644
--- a/public_html/libgit/class.pack.php
+++ b/public_html/libgit/class.pack.php
@@ -46,7 +46,14 @@ class GitPack
case OBJ_TAG:
// this is a compressed object
$data = fread($file, $size);
- return $this->repo->CreateObject(gzuncompress($data), $type, $size);
+ $uncompressed = gzuncompress($data);
+
+ if($uncompressed === false)
+ {
+ $uncompressed = $data;
+ }
+
+ return $this->repo->CreateObject($uncompressed, $type, $size);
break;
case OBJ_OFS_DELTA:
case OBJ_REF_DELTA:
diff --git a/public_html/libgit/class.repository.php b/public_html/libgit/class.repository.php
index 01bf1ef..c0091dc 100644
--- a/public_html/libgit/class.repository.php
+++ b/public_html/libgit/class.repository.php
@@ -10,20 +10,25 @@ class GitRepository
function GetObjectRaw($sha)
{
- return gzuncompress(
- file_get_contents(
- sprintf("{$this->path}/objects/%s/%s",
- substr($sha, 0, 2),
- substr($sha, 2)
- )));
+ $filename = sprintf("{$this->path}/objects/%s/%s", substr($sha, 0, 2), substr($sha, 2));
+ return gzuncompress(file_get_contents($filename));
}
function GetObject($sha)
{
- return $this->CreateObject($this->GetObjectRaw($sha));
+ $filename = sprintf("{$this->path}/objects/%s/%s", substr($sha, 0, 2), substr($sha, 2));
+
+ if(file_exists($filename))
+ {
+ return $this->CreateObject($this->GetObjectRaw($sha), null, null, $sha);
+ }
+ else
+ {
+ return $this->FindPackedObject($sha);
+ }
}
- function CreateObject($data, $type = null, $size = null)
+ function CreateObject($data, $type = null, $size = null, $sha)
{
if($type == null && $size == null)
{
@@ -64,19 +69,19 @@ class GitRepository
switch($type)
{
case "commit":
- return new GitCommit($this, $headerdata, $data);
+ return new GitCommit($this, $headerdata, $data, $sha);
break;
case "blob":
- return new GitBlob($this, $headerdata, $data);
+ return new GitBlob($this, $headerdata, $data, $sha);
break;
case "tree":
- return new GitTree($this, $headerdata, $data);
+ return new GitTree($this, $headerdata, $data, $sha);
break;
case "tag":
- return new GitTag($this, $headerdata, $data);
+ return new GitTag($this, $headerdata, $data, $sha);
break;
default:
- return new GitObject($this, $headerdata, $data);
+ return new GitObject($this, $headerdata, $data, $sha);
break;
}
}
@@ -141,6 +146,22 @@ class GitRepository
return $tags;
}
+ function GetPacks()
+ {
+ $packs = array();
+
+ foreach(scandir("{$this->path}/objects/pack/") as $pack)
+ {
+ if($pack != "." && $pack != ".." && substr($pack, strlen($pack) - 5) != ".pack")
+ {
+ $pack_name = substr($pack, 0, strlen($pack) - 4);
+ $packs[] = $pack_name;
+ }
+ }
+
+ return $packs;
+ }
+
function GetObjectForPath($origin, $path)
{
$path_parts = explode("/", $path);
@@ -188,4 +209,21 @@ class GitRepository
throw new GitInvalidOriginException("You can only use a GitTree hash as origin.");
}
}
+
+ function FindPackedObject($sha)
+ {
+ foreach($this->GetPacks() as $item)
+ {
+ $pack = new GitPack($this, $item);
+
+ try
+ {
+ return $pack->UnpackObject($sha);
+ }
+ catch (GitObjectNotFoundException $e)
+ {
+ // Silently ignore.
+ }
+ }
+ }
}
diff --git a/public_html/libgit/class.tag.php b/public_html/libgit/class.tag.php
index 2d68d59..814ba67 100644
--- a/public_html/libgit/class.tag.php
+++ b/public_html/libgit/class.tag.php
@@ -7,9 +7,9 @@ class GitTag extends GitObject
public $tag = "";
public $message = "";
- function __construct($repo, $headerdata, $data)
+ function __construct($repo, $headerdata, $data, $sha)
{
- parent::__construct($repo, $headerdata, $data);
+ parent::__construct($repo, $headerdata, $data, $sha);
$lines = explode("\n", $data);
$message_parts = array();
diff --git a/public_html/libgit/class.tree.php b/public_html/libgit/class.tree.php
index 1ce4dee..52cd8cf 100644
--- a/public_html/libgit/class.tree.php
+++ b/public_html/libgit/class.tree.php
@@ -3,9 +3,9 @@ class GitTree extends GitObject
{
public $elements = array();
- function __construct($repo, $headerdata, $data)
+ function __construct($repo, $headerdata, $data, $sha)
{
- parent::__construct($repo, $headerdata, $data);
+ parent::__construct($repo, $headerdata, $data, $sha);
$parsing_sha = false;
$sha_bytecount = 0;
diff --git a/public_html/test.php b/public_html/test.php
index c6820ad..aa310c7 100644
--- a/public_html/test.php
+++ b/public_html/test.php
@@ -2,7 +2,26 @@
require("libgit/base.php");
$repo = new GitRepository("/home/occupy/testrepo.git");
-pretty_dump($repo->GetTags());
+//pretty_dump($repo->GetTags());
+
+if(!empty($_GET['sha']))
+{
+ $sha = $_GET['sha'];
+}
+elseif(!empty($_GET['branch']))
+{
+ $sha = $repo->GetBranch($_GET['branch'])->sha;
+}
+elseif(!empty($_GET['tag']))
+{
+ $sha = $repo->GetTag($_GET['tag'])->sha;
+}
+else
+{
+ die();
+}
+
+pretty_dump($repo->GetObject($sha));
/*$pack = new GitPack($repo, "pack-8503a2b8cf6e60831dd012afd4d486eb1eddfef8");
pretty_dump($pack->UnpackObject("a6269a2ffd269289d7d026818511fab88718feff"));*/