Dereference commits in the tag list class, not the load strategy. Fixes #12
Dereference commits in the tag list class, not the load strategy. Fixes #12

Dereferencing commits in the tag list load strategy is too early. In particular, tags that point to other tags need to reference back into the tag list to get the tag object they point to. When triggering this from the strategy, the tag list hasn’t actually been fully loaded yet, so the tagged tag lookup fails.

--- a/include/git/taglist/TagList.class.php
+++ b/include/git/taglist/TagList.class.php
@@ -122,6 +122,21 @@
 		$this->dataLoaded = true;
 
 		list($this->refs, $this->commits) = $this->strategy->Load($this);
+		
+		if (!$this->commits) {
+			// dereference commits if the strategy doesn't do it for us
+			// TODO: is there a way to do this without introducing strategy specific logic in the core class?
+			$this->commits = array();
+			$objManager = $this->GetProject()->GetObjectManager();
+			foreach ($this->refs as $tag => $tagHash) {
+				$tagObj = $objManager->GetTag($tag, $tagHash);
+				$commitHash = $tagObj->GetCommitHash();
+				if (!empty($commitHash)) {
+					$this->commits[$tag] = $commitHash;
+				}
+			}
+		}
+		
 		foreach ($this->commits as $ref => $hash) $this->invertedRefs[$hash][] = $ref;
 	}
 

--- a/include/git/taglist/TagListLoad_Raw.class.php
+++ b/include/git/taglist/TagListLoad_Raw.class.php
@@ -18,16 +18,7 @@
 	public function Load($tagList)
 	{
 		$tags = $this->GetRefs($tagList, 'tags');
-		$commits = array();
-		$objManager = $tagList->GetProject()->GetObjectManager();
-		foreach ($tags as $tag => $tagHash) {
-			$tagObj = $objManager->GetTag($tag, $tagHash);
-			$commitHash = $tagObj->GetCommitHash();
-			if (!empty($commitHash)) {
-				$commits[$tag] = $commitHash;
-			}
-		}
-		return array($tags, $commits);
+		return array($tags, null);
 	}
 
 	/**

comments