Move most project references to be fetched off of project list
Move most project references to be fetched off of project list

--- a/include/git/Archive.class.php
+++ b/include/git/Archive.class.php
@@ -51,7 +51,7 @@
 	 *
 	 * @access protected
 	 */
-	protected $project = null;
+	protected $project;
 
 	/**
 	 * format
@@ -122,7 +122,7 @@
 		$this->SetProject($project);
 		$this->SetObject($gitObject);
 		if (!$this->project && $gitObject) {
-			$this->project = $gitObject->GetProject();
+			$this->project = $gitObject->GetProject()->GetProject();
 		}
 		$this->SetFormat($format);
 		$this->SetPath($path);
@@ -229,7 +229,7 @@
 	public function GetProject()
 	{
 		if ($this->project)
-			return $this->project;
+			return GitPHP_ProjectList::GetInstance()->GetProject($this->project);
 
 		return null;
 	}
@@ -244,7 +244,10 @@
 	 */
 	public function SetProject($project)
 	{
-		$this->project = $project;
+		if ($project)
+			$this->project = $project->GetProject();
+		else
+			$this->project = null;
 	}
 
 	/**

--- a/include/git/Blob.class.php
+++ b/include/git/Blob.class.php
@@ -528,7 +528,7 @@
 	 */
 	public function GetCacheKey()
 	{
-		return GitPHP_Blob::CacheKey($this->GetProject()->GetProject(), $this->hash);
+		return GitPHP_Blob::CacheKey($this->project, $this->hash);
 	}
 
 	/**

--- a/include/git/Commit.class.php
+++ b/include/git/Commit.class.php
@@ -1008,7 +1008,7 @@
 	 */
 	public function GetCacheKey()
 	{
-		return GitPHP_Commit::CacheKey($this->GetProject()->GetProject(), $this->hash);
+		return GitPHP_Commit::CacheKey($this->project, $this->hash);
 	}
 
 	/**

--- a/include/git/FileDiff.class.php
+++ b/include/git/FileDiff.class.php
@@ -199,7 +199,7 @@
 	 */
 	public function __construct($project, $fromHash, $toHash = '')
 	{
-		$this->project = $project;
+		$this->project = $project->GetProject();
 
 		if ($this->ParseDiffTreeLine($fromHash))
 			return;
@@ -210,6 +210,19 @@
 
 		$this->fromHash = $fromHash;
 		$this->toHash = $toHash;
+	}
+
+	/**
+	 * GetProject
+	 *
+	 * Gets the project
+	 *
+	 * @access public
+	 * @return mixed project
+	 */
+	public function GetProject()
+	{
+		return GitPHP_ProjectList::GetInstance()->GetProject($this->project);
 	}
 
 	/**
@@ -364,7 +377,7 @@
 		if (empty($this->fromHash))
 			return null;
 
-		return $this->project->GetBlob($this->fromHash);
+		return $this->GetProject()->GetBlob($this->fromHash);
 	}
 
 	/**
@@ -380,7 +393,7 @@
 		if (empty($this->toHash))
 			return null;
 
-		return $this->project->GetBlob($this->toHash);
+		return $this->GetProject()->GetBlob($this->toHash);
 	}
 
 	/**
@@ -747,7 +760,7 @@
 				$output = '--- ' . $fromName . "\n" . '+++ ' . $toName . "\n";
 			}
 
-			$cacheKey = 'project|' . $this->project->GetProject() . '|diff|' . $context . '|' . $this->fromHash . '|' . $this->toHash;
+			$cacheKey = 'project|' . $this->project . '|diff|' . $context . '|' . $this->fromHash . '|' . $this->toHash;
 			$diffOutput = GitPHP_Cache::GetObjectCacheInstance()->Get($cacheKey);
 			if ($diffOutput === false) {
 
@@ -824,7 +837,7 @@
 	 */
 	public function GetCommit()
 	{
-		return $this->project->GetCommit($this->commitHash);
+		return $this->GetProject()->GetCommit($this->commitHash);
 	}
 
 	/**

--- a/include/git/GitExe.class.php
+++ b/include/git/GitExe.class.php
@@ -74,6 +74,19 @@
 	}
 
 	/**
+	 * GetProject
+	 *
+	 * Gets the project
+	 *
+	 * @access public
+	 * @return mixed project
+	 */
+	public function GetProject()
+	{
+		return GitPHP_ProjectList::GetInstance()->GetProject($this->project);
+	}
+
+	/**
 	 * SetProject
 	 *
 	 * Sets the project for this executable
@@ -82,7 +95,10 @@
 	 */
 	public function SetProject($project = null)
 	{
-		$this->project = $project;
+		if ($project)
+			$this->project = $project->GetProject();
+		else
+			$this->project = null;
 	}
 
 	/**
@@ -139,7 +155,7 @@
 	{
 		$gitDir = '';
 		if ($this->project) {
-			$gitDir = '--git-dir=' . $this->project->GetPath();
+			$gitDir = '--git-dir=' . $this->GetProject()->GetPath();
 		}
 		
 		return $this->binary . ' ' . $gitDir . ' ' . $command . ' ' . implode(' ', $args);

--- a/include/git/GitObject.class.php
+++ b/include/git/GitObject.class.php
@@ -56,15 +56,6 @@
 	protected $abbreviatedHashLoaded = false;
 
 	/**
-	 * projectReferenced
-	 *
-	 * Stores whether the project has been referenced into a pointer
-	 *
-	 * @access protected
-	 */
-	protected $projectReferenced = false;
-
-	/**
 	 * __construct
 	 *
 	 * Instantiates object
@@ -77,7 +68,7 @@
 	 */
 	public function __construct($project, $hash)
 	{
-		$this->project = $project;
+		$this->project = $project->GetProject();
 		$this->SetHash($hash);
 	}
 
@@ -91,10 +82,7 @@
 	 */
 	public function GetProject()
 	{
-		if ($this->projectReferenced)
-			$this->DereferenceProject();
-
-		return $this->project;
+		return GitPHP_ProjectList::GetInstance()->GetProject($this->project);
 	}
 
 	/**
@@ -140,40 +128,6 @@
 	}
 
 	/**
-	 * ReferenceProject
-	 *
-	 * Turns the project object into a reference pointer
-	 *
-	 * @access private
-	 */
-	private function ReferenceProject()
-	{
-		if ($this->projectReferenced)
-			return;
-
-		$this->project = $this->project->GetProject();
-
-		$this->projectReferenced = true;
-	}
-
-	/**
-	 * DereferenceProject
-	 *
-	 * Turns the project reference pointer back into an object
-	 *
-	 * @access private
-	 */
-	private function DereferenceProject()
-	{
-		if (!$this->projectReferenced)
-			return;
-
-		$this->project = GitPHP_ProjectList::GetInstance()->GetProject($this->project);
-
-		$this->projectReferenced = false;
-	}
-
-	/**
 	 * __sleep
 	 *
 	 * Called to prepare the object for serialization
@@ -183,10 +137,7 @@
 	 */
 	public function __sleep()
 	{
-		if (!$this->projectReferenced)
-			$this->ReferenceProject();
-
-		return array('project', 'hash', 'projectReferenced');
+		return array('project', 'hash');
 	}
 
 	/**
@@ -199,13 +150,7 @@
 	 */
 	public function GetCacheKey()
 	{
-		$projKey = 'project|';
-		if ($this->projectReferenced)
-			$projKey .= $this->project;
-		else
-			$projKey .= $this->project->GetProject();
-
-		return $projKey;
+		return 'project|' . $this->project;
 	}
 
 }

--- a/include/git/Head.class.php
+++ b/include/git/Head.class.php
@@ -48,7 +48,7 @@
 	 */
 	public function GetCommit()
 	{
-		return $this->project->GetCommit($this->GetHash());
+		return $this->GetProject()->GetCommit($this->GetHash());
 	}
 	
 	/**

--- a/include/git/Pack.class.php
+++ b/include/git/Pack.class.php
@@ -71,7 +71,7 @@
 			throw new Exception(sprintf(__('Invalid hash %1$s'), $hash));
 		}
 		$this->hash = $hash;
-		$this->project = $project;
+		$this->project = $project->GetProject();
 
 		if (!file_exists($project->GetPath() . '/objects/pack/pack-' . $hash . '.idx')) {
 			throw new Exception('Pack index does not exist');
@@ -79,6 +79,19 @@
 		if (!file_exists($project->GetPath() . '/objects/pack/pack-' . $hash . '.pack')) {
 			throw new Exception('Pack file does not exist');
 		}
+	}
+
+	/**
+	 * GetProject
+	 *
+	 * Gets the project
+	 *
+	 * @access public
+	 * @return mixed project
+	 */
+	public function GetProject()
+	{
+		return GitPHP_ProjectList::GetInstance()->GetProject($this->project);
 	}
 
 	/**
@@ -127,7 +140,7 @@
 			return false;
 		}
 
-		$indexFile = $this->project->GetPath() . '/objects/pack/pack-' . $this->hash . '.idx';
+		$indexFile = $this->GetProject()->GetPath() . '/objects/pack/pack-' . $this->hash . '.idx';
 
 		if (isset($this->offsetCache[$hash])) {
 			return $this->offsetCache[$hash];
@@ -336,7 +349,7 @@
 			return false;
 		}
 
-		$pack = fopen($this->project->GetPath() . '/objects/pack/pack-' . $this->hash . '.pack', 'rb');
+		$pack = fopen($this->GetProject()->GetPath() . '/objects/pack/pack-' . $this->hash . '.pack', 'rb');
 		flock($pack, LOCK_SH);
 
 		$magic = fread($pack, 4);
@@ -437,7 +450,7 @@
 			 */
 			$hash = fread($pack, 20);
 			$hash = bin2hex($hash);
-			$base = $this->project->GetObject($hash, $type);
+			$base = $this->GetProject()->GetObject($hash, $type);
 
 			/*
 			 * then the gzipped delta data
@@ -515,7 +528,7 @@
 			return array($prefix);
 		}
 
-		$indexFile = $this->project->GetPath() . '/objects/pack/pack-' . $this->hash . '.idx';
+		$indexFile = $this->GetProject()->GetPath() . '/objects/pack/pack-' . $this->hash . '.idx';
 
 		$matches = array();
 

--- a/include/git/Ref.class.php
+++ b/include/git/Ref.class.php
@@ -54,7 +54,7 @@
 	 */
 	public function __construct($project, $refDir, $refName, $refHash = '')
 	{
-		$this->project = $project;
+		$this->project = $project->GetProject();
 		$this->refDir = $refDir;
 		$this->refName = $refName;
 		if (!empty($refHash)) {

--- a/include/git/Tag.class.php
+++ b/include/git/Tag.class.php
@@ -560,7 +560,7 @@
 	 */
 	public function GetCacheKey()
 	{
-		return GitPHP_Tag::CacheKey($this->GetProject()->GetProject(), $this->refName);
+		return GitPHP_Tag::CacheKey($this->project, $this->refName);
 	}
 
 	/**

--- a/include/git/Tree.class.php
+++ b/include/git/Tree.class.php
@@ -256,7 +256,7 @@
 	 */
 	public function GetCacheKey()
 	{
-		return GitPHP_Tree::CacheKey($this->GetProject()->GetProject(), $this->hash);
+		return GitPHP_Tree::CacheKey($this->project, $this->hash);
 	}
 
 	/**

--- a/include/git/TreeDiff.class.php
+++ b/include/git/TreeDiff.class.php
@@ -90,9 +90,9 @@
 	 */
 	public function __construct($project, $toHash, $fromHash = '', $renames = false)
 	{
-		$this->project = $project;
-
-		$toCommit = $this->project->GetCommit($toHash);
+		$this->project = $project->GetProject();
+
+		$toCommit = $project->GetCommit($toHash);
 		$this->toHash = $toHash;
 
 		if (empty($fromHash)) {
@@ -101,7 +101,6 @@
 				$this->fromHash = $parent->GetHash();
 			}
 		} else {
-			$fromCommit = $this->project->GetCommit($fromHash);
 			$this->fromHash = $fromHash;
 		}
 
@@ -109,6 +108,19 @@
 	}
 
 	/**
+	 * GetProject
+	 *
+	 * Gets the project
+	 *
+	 * @access public
+	 * @return mixed project
+	 */
+	public function GetProject()
+	{
+		return GitPHP_ProjectList::GetInstance()->GetProject($this->project);
+	}
+
+	/**
 	 * ReadData
 	 *
 	 * Reads the tree diff data
@@ -121,7 +133,7 @@
 
 		$this->fileDiffs = array();
 
-		$exe = new GitPHP_GitExe($this->project);
+		$exe = new GitPHP_GitExe($this->GetProject());
 
 		$args = array();
 
@@ -141,7 +153,7 @@
 			$trimmed = trim($line);
 			if ((strlen($trimmed) > 0) && (substr_compare($trimmed, ':', 0, 1) === 0)) {
 				try {
-					$this->fileDiffs[] = new GitPHP_FileDiff($this->project, $trimmed);
+					$this->fileDiffs[] = new GitPHP_FileDiff($this->GetProject(), $trimmed);
 				} catch (Exception $e) {
 				}
 			}

comments