Bring back tag badges - fixes #6
Bring back tag badges - fixes #6

This copy pasted code from the head list won’t really work for tags. Heads are easy in that they always point to a commit. Tags are more complicated in that they’re objects themselves, which then point to commits or even other tags. So you can’t just say the hash of the ref is the commit, you have to read the tag to dereference into the commit.

--- a/include/git/taglist/TagList.class.php
+++ b/include/git/taglist/TagList.class.php
@@ -96,12 +96,12 @@
 		foreach ($tagNames as $tag) {
 			if (isset($this->commits[$tag])) {
 				if ($this->commits[$tag] == $commitHash) {
-					$tagObj = $this->project->GetObjectManager()->GetTag($tag, $commitHash);
+					$tagObj = $this->project->GetObjectManager()->GetTag($tag, $this->refs[$tag]);
 					$tagObj->SetCommitHash($this->commits[$tag]);
 					$tags[] = $tagObj;
 				}
 			} else {
-				$tagObj = $this->project->GetObjectManager()->GetTag($tag, $commitHash);
+				$tagObj = $this->project->GetObjectManager()->GetTag($tag, $this->refs[$tag]);
 				$tagCommitHash = $tagObj->GetCommitHash();
 				if (!empty($tagCommitHash)) {
 					$this->commits[$tag] = $tagCommitHash;
@@ -122,7 +122,7 @@
 		$this->dataLoaded = true;
 
 		list($this->refs, $this->commits) = $this->strategy->Load($this);
-		foreach ($this->refs as $ref => $hash) $this->invertedRefs[$hash][] = $ref;
+		foreach ($this->commits as $ref => $hash) $this->invertedRefs[$hash][] = $ref;
 	}
 
 	/**

--- a/include/git/taglist/TagListLoad_Git.class.php
+++ b/include/git/taglist/TagListLoad_Git.class.php
@@ -17,7 +17,16 @@
 	 */
 	public function Load($tagList)
 	{
-		return $this->GetRefs($tagList, 'tags');
+		list($tags, $commits) = $this->GetRefs($tagList, 'tags');
+		
+		foreach ($tags as $tag => $tagHash) {
+			if (empty($commits[$tag])) {
+				// tag has no dereferenced hash - must be a light tag
+				$commits[$tag] = $tagHash;
+			}
+		}
+		
+		return array($tags, $commits);
 	}
 
 	/**

--- a/include/git/taglist/TagListLoad_Raw.class.php
+++ b/include/git/taglist/TagListLoad_Raw.class.php
@@ -17,7 +17,17 @@
 	 */
 	public function Load($tagList)
 	{
-		return array($this->GetRefs($tagList, 'tags'), array());
+		$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);
 	}
 
 	/**

comments