Inject objectloader directly instead of getting it off of project
Inject objectloader directly instead of getting it off of project

--- a/include/git/GitObjectManager.class.php
+++ b/include/git/GitObjectManager.class.php
@@ -45,6 +45,13 @@
 	protected $exe;
 
 	/**
+	 * Object loader
+	 *
+	 * @var GitPHP_GitObjectLoader
+	 */
+	protected $objectLoader;
+
+	/**
 	 * Constructor
 	 *
 	 * @param GitPHP_Project $project project
@@ -65,6 +72,16 @@
 	public function SetExe($exe)
 	{
 		$this->exe = $exe;
+	}
+
+	/**
+	 * Set object loader
+	 *
+	 * @param GitPHP_GitObjectLoader $objectLoader object loader
+	 */
+	public function SetObjectLoader($objectLoader)
+	{
+		$this->objectLoader = $objectLoader;
 	}
 
 	/**
@@ -165,7 +182,7 @@
 			if ($this->compat) {
 				$strategy = new GitPHP_CommitLoad_Git($this->exe);
 			} else {
-				$strategy = new GitPHP_CommitLoad_Raw($this->project->GetObjectLoader(), $this->exe);
+				$strategy = new GitPHP_CommitLoad_Raw($this->objectLoader, $this->exe);
 			}
 
 			if ($commit) {
@@ -213,7 +230,7 @@
 			if ($this->compat) {
 				$strategy = new GitPHP_TagLoad_Git($this->exe);
 			} else {
-				$strategy = new GitPHP_TagLoad_Raw($this->project->GetObjectLoader());
+				$strategy = new GitPHP_TagLoad_Raw($this->objectLoader);
 			}
 
 			if ($tagObj) {
@@ -287,7 +304,7 @@
 			if ($this->compat) {
 				$strategy = new GitPHP_BlobLoad_Git($this->exe);
 			} else {
-				$strategy = new GitPHP_BlobLoad_Raw($this->project->GetObjectLoader());
+				$strategy = new GitPHP_BlobLoad_Raw($this->objectLoader);
 			}
 
 			if ($blob) {
@@ -332,7 +349,7 @@
 			if ($this->compat) {
 				$strategy = new GitPHP_TreeLoad_Git($this->exe);
 			} else {
-				$strategy = new GitPHP_TreeLoad_Raw($this->project->GetObjectLoader(), $this->exe);
+				$strategy = new GitPHP_TreeLoad_Raw($this->objectLoader, $this->exe);
 			}
 			if ($tree) {
 				$tree->SetProject($this->project);

--- a/include/git/project/Project.class.php
+++ b/include/git/project/Project.class.php
@@ -192,13 +192,6 @@
 /*}}}2*/
 
 	/**
-	 * The raw git object loader
-	 *
-	 * @var GitPHP_GitObjectLoader
-	 */
-	protected $objectLoader;
-
-	/**
 	 * The git object manager
 	 *
 	 * @var GitPHP_GitObjectManager
@@ -786,29 +779,6 @@
 /* object loader/manager methods {{{2*/
 
 	/**
-	 * Gets the git object loader for this project
-	 *
-	 * @return GitPHP_GitObjectLoader
-	 */
-	public function GetObjectLoader()
-	{
-		return $this->objectLoader;
-	}
-
-	/**
-	 * Sets the git object loader for this project
-	 *
-	 * @param GitPHP_GitObjectLoader $objectLoader object loader
-	 */
-	public function SetObjectLoader($objectLoader)
-	{
-		if ($objectLoader && ($objectLoader->GetProject() !== $this))
-			throw new Exception('Invalid object loader for this project');
-
-		$this->objectLoader = $objectLoader;
-	}
-
-	/**
 	 * Get the git object manager for this project
 	 *
 	 * @return GitPHP_GitObjectManager

--- a/include/git/project/ProjectLoad_Raw.class.php
+++ b/include/git/project/ProjectLoad_Raw.class.php
@@ -9,6 +9,26 @@
  */
 class GitPHP_ProjectLoad_Raw implements GitPHP_ProjectLoadStrategy_Interface
 {
+	/**
+	 * Git object loader
+	 *
+	 * @var GitPHP_GitObjectLoader
+	 */
+	protected $objectLoader;
+
+	/**
+	 * Constructor
+	 *
+	 * @param GitPHP_GitObjectLoader $objectLoader object loader
+	 */
+	public function __construct($objectLoader)
+	{
+		if (!$objectLoader)
+			throw new Exception('Git object loader is required');
+
+		$this->objectLoader = $objectLoader;
+	}
+
 	/**
 	 * Load a project's epoch
 	 *
@@ -74,7 +94,7 @@
 			return $abbrevHash;
 		}
 
-		return $project->GetObjectLoader()->ExpandHash($abbrevHash);
+		return $this->objectLoader->ExpandHash($abbrevHash);
 	}
 
 	/**
@@ -112,7 +132,7 @@
 			return $prefix;
 		}
 
-		return $project->GetObjectLoader()->EnsureUniqueHash($hash, $prefix);
+		return $this->objectLoader->EnsureUniqueHash($hash, $prefix);
 	}
 }
 

--- a/include/git/projectlist/ProjectListBase.class.php
+++ b/include/git/projectlist/ProjectListBase.class.php
@@ -276,10 +276,12 @@
 
 		$compat = $project->GetCompat();
 
+		$loader = null;
 		if ($compat) {
 			$project->SetStrategy(new GitPHP_ProjectLoad_Git($this->exe));
 		} else {
-			$project->SetStrategy(new GitPHP_ProjectLoad_Raw());
+			$loader = new GitPHP_GitObjectLoader($project);
+			$project->SetStrategy(new GitPHP_ProjectLoad_Raw($loader));
 		}
 
 		$headListStrategy = null;
@@ -300,13 +302,11 @@
 		$tagList = new GitPHP_TagList($project, $tagListStrategy);
 		$project->SetTagList($tagList);
 
-		if (!$compat) {
-			$loader = new GitPHP_GitObjectLoader($project);
-			$project->SetObjectLoader($loader);
-		}
-
 		$manager = new GitPHP_GitObjectManager($project);
 		$manager->SetCompat($compat);
+		if (!$compat) {
+			$manager->SetObjectLoader($loader);
+		}
 		$manager->SetExe($this->exe);
 		if ($this->memoryCache) {
 			$manager->SetMemoryCache($this->memoryCache);

comments