Browse Source

Add more classes to php-libgit

master
Sven Slootweg 10 years ago
parent
commit
e5591fa56f
  1. 3
      public_html/libgit/base.php
  2. 8
      public_html/libgit/class.blob.php
  3. 8
      public_html/libgit/class.tag.php
  4. 14
      public_html/libgit/class.tree.element.php
  5. 47
      public_html/libgit/class.tree.php
  6. BIN
      public_html/test.hex
  7. 5
      public_html/test.php

3
public_html/libgit/base.php

@ -25,7 +25,10 @@ function sha1_from_bin($bin)
require(dirname(__FILE__) . "/class.repository.php");
require(dirname(__FILE__) . "/class.object.php");
require(dirname(__FILE__) . "/class.blob.php");
require(dirname(__FILE__) . "/class.tag.php");
require(dirname(__FILE__) . "/class.tree.php");
require(dirname(__FILE__) . "/class.tree.element.php");
require(dirname(__FILE__) . "/class.commit.php");
require(dirname(__FILE__) . "/class.actor.php");
?>

8
public_html/libgit/class.blob.php

@ -0,0 +1,8 @@
<?php
class GitBlob extends GitObject
{
function __construct($repo, $headerdata, $data)
{
parent::__construct($repo, $headerdata, $data);
}
}

8
public_html/libgit/class.tag.php

@ -0,0 +1,8 @@
<?php
class GitTag extends GitObject
{
function __construct($repo, $headerdata, $data)
{
parent::__construct($repo, $headerdata, $data);
}
}

14
public_html/libgit/class.tree.element.php

@ -0,0 +1,14 @@
<?php
class GitTreeElement
{
public $mode = "";
public $filename = "";
public $hash = "";
function __construct($mode, $filename, $hash)
{
$this->mode = $mode;
$this->filename = $filename;
$this->hash = $hash;
}
}

47
public_html/libgit/class.tree.php

@ -1,5 +1,50 @@
<?php
class GitTree extends GitObject
{
public $elements = array();
function __construct($repo, $headerdata, $data)
{
parent::__construct($repo, $headerdata, $data);
$parsing_sha = false;
$sha_bytecount = 0;
$lines = array();
$current_line = "";
for($i = 0; $i < strlen($data); $i++)
{
$char = $data[$i];
$current_line .= $char;
if(ord($char) == 0)
{
$parsing_sha = true;
}
else
{
if($parsing_sha === true)
{
$sha_bytecount += 1;
}
if($sha_bytecount == 20)
{
$parsing_sha = false;
$lines[] = $current_line;
$current_line = "";
$sha_bytecount = 0;
}
}
}
$lines[] = $current_line;
foreach($lines as $line)
{
list($metadata, $binhash) = explode("\0", $line, 2);
list($mode, $filename) = explode(" ", $metadata, 2);
$hash = sha1_from_bin($binhash);
$this->elements[] = new GitTreeElement($mode, $filename, $hash);
}
}
}

BIN
public_html/test.hex

5
public_html/test.php

@ -2,7 +2,8 @@
require("libgit/base.php");
$s = new GitRepository("/home/occupy/testrepo.git");
pretty_dump($s->GetObject("54e03e490b1bee1c154c3545bf258cab0629ee02"));
/*pretty_dump($s->GetObject("54e03e490b1bee1c154c3545bf258cab0629ee02"));
pretty_dump($s->GetObject("98d99489382a3541e6783bb2083554785f3eb72a"));
pretty_dump($s->GetObject("9d8e0ba4a30f6a5d775a879c42c7de5aed4530c6"));
pretty_dump($s->GetObject("710bfee4440517255475bf7c5454c0bdbb3b3e56"));
pretty_dump($s->GetObject("710bfee4440517255475bf7c5454c0bdbb3b3e56"));*/
pretty_dump($s->GetObject("dba13ed2ddf783ee8118c6a581dbf75305f816a3"));
Loading…
Cancel
Save