Browse Source

Save reference to repository in each object

master
Sven Slootweg 10 years ago
parent
commit
791ff588a8
  1. 4
      public_html/libgit/class.commit.php
  2. 4
      public_html/libgit/class.object.php
  3. 10
      public_html/libgit/class.repository.php
  4. 1
      public_html/test.php

4
public_html/libgit/class.commit.php

@ -7,9 +7,9 @@ class GitCommit extends GitObject
public $message = "";
public $parents = array();
function __construct($headerdata, $data)
function __construct($repo, $headerdata, $data)
{
parent::__construct($headerdata, $data);
parent::__construct($repo, $headerdata, $data);
$lines = explode("\n", $data);
$message_parts = array();

4
public_html/libgit/class.object.php

@ -3,9 +3,11 @@ class GitObject
{
public $rawdata = "";
public $size = 0;
public $repo = null;
function __construct($headerdata, $data)
function __construct($repo, $headerdata, $data)
{
$this->repo = $repo;
$this->size = (int)$headerdata;
$this->rawdata = $data;
}

10
public_html/libgit/class.repository.php

@ -35,19 +35,19 @@ class GitRepository
switch($type)
{
case "commit":
return new GitCommit($headerdata, $data);
return new GitCommit($this, $headerdata, $data);
break;
case "blob":
return new GitBlob($headerdata, $data);
return new GitBlob($this, $headerdata, $data);
break;
case "tree":
return new GitTree($headerdata, $data);
return new GitTree($this, $headerdata, $data);
break;
case "tag":
return new GitTag($headerdata, $data);
return new GitTag($this, $headerdata, $data);
break;
default:
return new GitObject($headerdata, $data);
return new GitObject($this, $headerdata, $data);
break;
}
}

1
public_html/test.php

@ -3,3 +3,4 @@ require("libgit/base.php");
$s = new GitRepository("/home/occupy/testrepo.git");
pretty_dump($s->GetObject("54e03e490b1bee1c154c3545bf258cab0629ee02"));
pretty_dump($s->GetObject("9d8e0ba4a30f6a5d775a879c42c7de5aed4530c6"));
Loading…
Cancel
Save