Fix commit lookups where a commit is referenced by the name of a ref
Fix commit lookups where a commit is referenced by the name of a ref
rather than a commit hash

Bug #78

--- a/include/git/Project.class.php
+++ b/include/git/Project.class.php
@@ -590,26 +590,43 @@
 			$head = $this->GetHead(substr($hash, 11));
 			if ($head != null)
 				return $head->GetCommit();
+			return null;
 		} else if (substr_compare($hash, 'refs/tags/', 0, 10) === 0) {
 			$tag = $this->GetTag(substr($hash, 10));
 			if ($tag != null) {
-				$obj = $tag->GetObject();
+				$obj = $tag->GetCommit();
 				if ($obj != null) {
 					return $obj;
 				}
 			}
-		}
-
-		if (!isset($this->commitCache[$hash])) {
-			$cacheKey = 'project|' . $this->project . '|commit|' . $hash;
-			$cached = GitPHP_Cache::GetInstance()->Get($cacheKey);
-			if ($cached)
-				$this->commitCache[$hash] = $cached;
-			else
-				$this->commitCache[$hash] = new GitPHP_Commit($this, $hash);
-		}
-
-		return $this->commitCache[$hash];
+			return null;
+		}
+
+		if (preg_match('/[0-9a-f]{40}/i', $hash)) {
+
+			if (!isset($this->commitCache[$hash])) {
+				$cacheKey = 'project|' . $this->project . '|commit|' . $hash;
+				$cached = GitPHP_Cache::GetInstance()->Get($cacheKey);
+				if ($cached)
+					$this->commitCache[$hash] = $cached;
+				else
+					$this->commitCache[$hash] = new GitPHP_Commit($this, $hash);
+			}
+
+			return $this->commitCache[$hash];
+
+		}
+
+		if (!$this->readRefs)
+			$this->ReadRefList();
+
+		if (isset($this->heads['refs/heads/' . $hash]))
+			return $this->heads['refs/heads/' . $hash]->GetCommit();
+
+		if (isset($this->tags['refs/tags/' . $hash]))
+			return $this->tags['refs/tags/' . $hash]->GetCommit();
+
+		return null;
 	}
 
 	/**

comments