Merge branch 'stylesheet'
Merge branch 'stylesheet'

--- a/include/controller/Controller_Project.class.php
+++ b/include/controller/Controller_Project.class.php
@@ -108,14 +108,22 @@
 			$this->tpl->assign('revlist', $revlist);
 		}
 
-		$taglist = $this->project->GetTags();
-		if (isset($taglist) && (count($taglist) > 0)) {
-			$this->tpl->assign("taglist",$taglist);
+		$taglist = $this->project->GetTags(17);
+		if ($taglist) {
+			if (count($taglist) > 16) {
+				$this->tpl->assign('hasmoretags', true);
+				$taglist = array_slice($taglist, 0, 16);
+			}
+			$this->tpl->assign('taglist', $taglist);
 		}
 
-		$headlist = $this->project->GetHeads();
-		if (isset($headlist) && (count($headlist) > 0)) {
-			$this->tpl->assign("headlist",$headlist);
+		$headlist = $this->project->GetHeads(17);
+		if ($headlist) {
+			if (count($headlist) > 17) {
+				$this->tpl->assign('hasmoreheads', true);
+				$headlist = array_slice($headlist, 0, 16);
+			}
+			$this->tpl->assign('headlist', $headlist);
 		}
 	}
 

--- a/include/git/Commit.class.php
+++ b/include/git/Commit.class.php
@@ -508,7 +508,7 @@
 
 		if (!empty($this->committerEpoch))
 			return time() - $this->committerEpoch;
-		
+
 		return '';
 	}
 
@@ -603,11 +603,11 @@
 	{
 		$heads = array();
 
-		$projectHeads = $this->GetProject()->GetHeads();
-
-		foreach ($projectHeads as $head) {
-			if ($head->GetCommit()->GetHash() === $this->hash) {
-				$heads[] = $head;
+		$projectRefs = $this->GetProject()->GetRefs('heads');
+
+		foreach ($projectRefs as $ref) {
+			if ($ref->GetHash() == $this->hash) {
+				$heads[] = $ref;
 			}
 		}
 
@@ -626,11 +626,11 @@
 	{
 		$tags = array();
 
-		$projectTags = $this->GetProject()->GetTags();
-
-		foreach ($projectTags as $tag) {
-			if ($tag->GetCommit()->GetHash() === $this->hash) {
-				$tags[] = $tag;
+		$projectRefs = $this->GetProject()->GetRefs('tags');
+
+		foreach ($projectRefs as $ref) {
+			if ($ref->GetCommit()->GetHash() === $this->hash) {
+				$tags[] = $ref;
 			}
 		}
 
@@ -759,7 +759,7 @@
 
 		GitPHP_Cache::GetInstance()->Set($this->GetCacheKey(), $this);
 	}
-	
+
 	/**
 	 * SearchFilenames
 	 *
@@ -824,7 +824,7 @@
 		$args[] = '-e';
 		$args[] = $pattern;
 		$args[] = $this->hash;
-		
+
 		$lines = explode("\n", $exe->Execute(GIT_GREP, $args));
 
 		$results = array();

--- a/include/git/Head.class.php
+++ b/include/git/Head.class.php
@@ -58,7 +58,7 @@
 	public function GetCommit()
 	{
 		if (!$this->commit) {
-			$this->commit = $this->project->GetCommit($this->hash);
+			$this->commit = $this->project->GetCommit($this->GetHash());
 		}
 
 		return $this->commit;

--- a/include/git/Project.class.php
+++ b/include/git/Project.class.php
@@ -116,6 +116,15 @@
 	protected $readHeadRef = false;
 
 	/**
+	 * tags
+	 *
+	 * Stores the tags for the project
+	 *
+	 * @access protected
+	 */
+	protected $tags = array();
+
+	/**
 	 * heads
 	 *
 	 * Stores the heads for the project
@@ -125,31 +134,13 @@
 	protected $heads = array();
 
 	/**
-	 * readHeads
-	 *
-	 * Stores whether heads have been read yet
-	 *
-	 * @access protected
-	 */
-	protected $readHeads = false;
-
-	/**
-	 * tags
-	 *
-	 * Stores the tags for the project
-	 *
-	 * @access protected
-	 */
-	protected $tags = array();
-
-	/**
-	 * readTags
-	 *
-	 * Stores whether tags have been read yet
-	 *
-	 * @access protected
-	 */
-	protected $readTags = false;
+	 * readRefs
+	 *
+	 * Stores whether refs have been read yet
+	 *
+	 * @access protected
+	 */
+	protected $readRefs = false;
 
 	/**
 	 * cloneUrl
@@ -704,78 +695,42 @@
 	}
 
 	/**
-	 * GetTags
-	 *
-	 * Gets list of tags for this project
-	 *
-	 * @access public
-	 * @return array array of tags
-	 */
-	public function GetTags()
-	{
-		if (!$this->readTags)
-			$this->ReadTagList();
-
-		return $this->tags;
-	}
-
-	/**
-	 * GetTag
-	 *
-	 * Gets a single tag
-	 *
-	 * @access public
-	 * @param string $tag tag to find
-	 * @return mixed tag object
-	 */
-	public function GetTag($tag)
-	{
-		if (empty($tag))
-			return null;
-
-		if (!isset($this->tags[$tag])) {
-			$this->LoadTag($tag);
-		}
-
-		return $this->tags[$tag];
-	}
-
-	/**
-	 * LoadTag
-	 *
-	 * Attempts to load a cached tag, or creates a new object
-	 *
-	 * @access private
-	 * @param string $tag tag to find
-	 * @return mixed tag object
-	 */
-	private function LoadTag($tag)
-	{
-		if (empty($tag))
-			return;
-
-		$cacheKey = 'project|' . $this->project . '|tag|' . $tag;
-		$cached = GitPHP_Cache::GetInstance()->Get($cacheKey);
-		if ($cached) {
-			$this->tags[$tag] = $cached;
-		} else {
-			$this->tags[$tag] = new GitPHP_Tag($this, $tag);
-		}
-	}
-
-	/**
-	 * ReadTagList
-	 *
-	 * Reads tag list
-	 *
-	 * @access protected
-	 */
-	protected function ReadTagList()
-	{
-		$this->readTags = true;
+	 * GetRefs
+	 *
+	 * Gets the list of refs for the project
+	 *
+	 * @access public
+	 * @param string $type type of refs to get
+	 * @return array array of refs
+	 */
+	public function GetRefs($type = '')
+	{
+		if (!$this->readRefs)
+			$this->ReadRefList();
+
+		if ($type == 'tags') {
+			return $this->tags;
+		} else if ($type == 'heads') {
+			return $this->heads;
+		}
+
+		return array_merge($this->heads, $this->tags);
+	}
+
+	/**
+	 * ReadRefList
+	 *
+	 * Reads the list of refs for this project
+	 *
+	 * @access protected
+	 */
+	public function ReadRefList()
+	{
+		$this->readRefs = true;
 
 		$exe = new GitPHP_GitExe($this);
 		$args = array();
+		$args[] = '--heads';
 		$args[] = '--tags';
 		$args[] = '--dereference';
 		$ret = $exe->Execute(GIT_SHOW_REF, $args);
@@ -784,46 +739,150 @@
 		$lines = explode("\n", $ret);
 
 		foreach ($lines as $line) {
-			if (preg_match('/^([0-9a-fA-F]{40}) refs\/tags\/([^^]+)(\^{})?$/', $line, $regs)) {
+			if (preg_match('/^([0-9a-fA-F]{40}) refs\/(tags|heads)\/([^^]+)(\^{})?$/', $line, $regs)) {
 				try {
-					if ((!empty($regs[3])) && ($regs[3] == '^{}')) {
-						$derefCommit = $this->GetCommit($regs[1]);
-						if ($derefCommit && isset($this->tags[$regs[2]])) {
-							$this->tags[$regs[2]]->SetCommit($derefCommit);
+					$key = 'refs/' . $regs[2] . '/' . $regs[3];
+					if ($regs[2] == 'tags') {
+						if ((!empty($regs[4])) && ($regs[4] == '^{}')) {
+							$derefCommit = $this->GetCommit($regs[1]);
+							if ($derefCommit && isset($this->tags[$key])) {
+								$this->tags[$key]->SetCommit($derefCommit);
+							}
+								
+						} else if (!isset($this->tags[$key])) {
+							$this->tags[$key] = $this->LoadTag($regs[3], $regs[1]);
 						}
-							
-					} else if (!isset($this->tags[$regs[2]])) {
-							$this->LoadTag($regs[2]);
-							if (isset($this->tags[$regs[2]])) {
-								$tagHash = $this->tags[$regs[2]]->GetHash();
-								if (empty($tagHash)) {
-									// New non-cached tag object
-									$this->tags[$regs[2]]->SetHash($regs[1]);
-								}
-							}
+					} else if ($regs[2] == 'heads') {
+						$this->heads[$key] = new GitPHP_Head($this, $regs[3], $regs[1]);
 					}
 				} catch (Exception $e) {
 				}
 			}
 		}
-
-		uasort($this->tags, array('GitPHP_Tag', 'CompareAge'));
+	}
+
+	/**
+	 * GetTags
+	 *
+	 * Gets list of tags for this project by age descending
+	 *
+	 * @access public
+	 * @param integer $count number of tags to load
+	 * @return array array of tags
+	 */
+	public function GetTags($count = 0)
+	{
+		if (!$this->readRefs)
+			$this->ReadRefList();
+
+		$exe = new GitPHP_GitExe($this);
+		$args = array();
+		$args[] = '--sort=-creatordate';
+		$args[] = '--format="%(refname)"';
+		if ($count > 0) {
+			$args[] = '--count=' . $count;
+		}
+		$args[] = '--';
+		$args[] = 'refs/tags';
+		$ret = $exe->Execute(GIT_FOR_EACH_REF, $args);
+		unset($exe);
+
+		$lines = explode("\n", $ret);
+
+		$tags = array();
+
+		foreach ($lines as $ref) {
+			if (isset($this->tags[$ref])) {
+				$tags[] = $this->tags[$ref];
+			}
+		}
+
+		return $tags;
+	}
+
+	/**
+	 * GetTag
+	 *
+	 * Gets a single tag
+	 *
+	 * @access public
+	 * @param string $tag tag to find
+	 * @return mixed tag object
+	 */
+	public function GetTag($tag)
+	{
+		if (empty($tag))
+			return null;
+
+		$key = 'refs/tags/' . $tag;
+
+		if (!isset($this->tags[$key])) {
+			$this->tags[$key] = $this->LoadTag($tag);
+		}
+
+		return $this->tags[$key];
+	}
+
+	/**
+	 * LoadTag
+	 *
+	 * Attempts to load a cached tag, or creates a new object
+	 *
+	 * @access private
+	 * @param string $tag tag to find
+	 * @return mixed tag object
+	 */
+	private function LoadTag($tag, $hash = '')
+	{
+		if (empty($tag))
+			return;
+
+		$cacheKey = 'project|' . $this->project . '|tag|' . $tag;
+		$cached = GitPHP_Cache::GetInstance()->Get($cacheKey);
+		if ($cached) {
+			return $cached;
+		} else {
+			return new GitPHP_Tag($this, $tag, $hash);
+		}
 	}
 
 	/**
 	 * GetHeads
 	 *
-	 * Gets list of heads for this project
-	 *
-	 * @access public
+	 * Gets list of heads for this project by age descending
+	 *
+	 * @access public
+	 * @param integer $count number of tags to load
 	 * @return array array of heads
 	 */
-	public function GetHeads()
-	{
-		if (!$this->readHeads)
-			$this->ReadHeadList();
-
-		return $this->heads;
+	public function GetHeads($count = 0)
+	{
+		if (!$this->readRefs)
+			$this->ReadRefList();
+
+		$exe = new GitPHP_GitExe($this);
+		$args = array();
+		$args[] = '--sort=-committerdate';
+		$args[] = '--format="%(refname)"';
+		if ($count > 0) {
+			$args[] = '--count=' . $count;
+		}
+		$args[] = '--';
+		$args[] = 'refs/heads';
+		$ret = $exe->Execute(GIT_FOR_EACH_REF, $args);
+		unset($exe);
+
+		$lines = explode("\n", $ret);
+
+		$heads = array();
+
+		foreach ($lines as $ref) {
+			if (isset($this->heads[$ref])) {
+				$heads[] = $this->heads[$ref];
+			}
+		}
+
+		return $heads;
 	}
 
 	/**
@@ -840,48 +899,13 @@
 		if (empty($head))
 			return null;
 
-		if (!$this->readHeads)
-			$this->ReadHeadList();
-
-		foreach ($this->heads as $h) {
-			if ($h->GetName() === $head) {
-				return $h;
-			}
-		}
-		
-		return null;
-	}
-
-	/**
-	 * ReadHeadList
-	 *
-	 * Reads head list
-	 *
-	 * @access protected
-	 */
-	protected function ReadHeadList()
-	{
-		$this->readHeads = true;
-
-		$exe = new GitPHP_GitExe($this);
-		$args = array();
-		$args[] = '--heads';
-		$ret = $exe->Execute(GIT_SHOW_REF, $args);
-		unset($exe);
-
-		$lines = explode("\n", $ret);
-
-		foreach ($lines as $line) {
-			if (preg_match('/^([0-9a-fA-F]{40}) refs\/heads\/(.+)$/', $line, $regs)) {
-				try {
-					$this->heads[] = new GitPHP_Head($this, $regs[2], $regs[1]);
-				} catch (Exception $e) {
-				}
-			}
-		}
-
-		usort($this->heads, array('GitPHP_Head', 'CompareAge'));
-
+		$key = 'refs/heads/' . $head;
+
+		if (!isset($this->heads[$key])) {
+			$this->heads[$key] = new GitPHP_Head($this, $head);
+		}
+
+		return $this->heads[$key];
 	}
 
 	/**

--- a/include/git/Tag.class.php
+++ b/include/git/Tag.class.php
@@ -158,14 +158,17 @@
 	 */
 	public function GetCommit()
 	{
-		if (!$this->dataRead)
-			$this->ReadData();
-
 		if ($this->commitReferenced)
 			$this->DereferenceCommit();
 
-		if (!$this->commit)
-			$this->ReadCommit();
+		if ($this->commit)
+			return $this->commit;
+
+		if (!$this->dataRead) {
+			$this->ReadData();
+			if ($this->commitReferenced)
+				$this->DereferenceCommit();
+		}
 
 		return $this->commit;
 	}
@@ -305,7 +308,7 @@
 		if (!$this->object)
 			return true;
 
-		return $this->object->GetHash() === $this->hash;
+		return $this->object->GetHash() === $this->GetHash();
 	}
 
 	/**
@@ -322,12 +325,12 @@
 		$exe = new GitPHP_GitExe($this->GetProject());
 		$args = array();
 		$args[] = '-t';
-		$args[] = $this->hash;
+		$args[] = $this->GetHash();
 		$ret = trim($exe->Execute(GIT_CAT_FILE, $args));
 		
 		if ($ret === 'commit') {
 			/* light tag */
-			$this->object = $this->GetProject()->GetCommit($this->hash);
+			$this->object = $this->GetProject()->GetCommit($this->GetHash());
 			$this->commit = $this->object;
 			$this->type = 'commit';
 			GitPHP_Cache::GetInstance()->Set($this->GetCacheKey(), $this);
@@ -416,7 +419,7 @@
 	 */
 	private function ReadCommit()
 	{
-		$exe = new GitPHP_GitExe($this);
+		$exe = new GitPHP_GitExe($this->GetProject());
 		$args = array();
 		$args[] = '--tags';
 		$args[] = '--dereference';

--- a/templates/headlist.tpl
+++ b/templates/headlist.tpl
@@ -12,17 +12,18 @@
  <table cellspacing="0">
    {* Loop and display each head *}
    {foreach from=$headlist item=head name=heads}
-     {if ($max > 0) && ($smarty.foreach.heads.iteration == $max)}
-       <td><a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=heads">&hellip;</a></td>
-     {elseif ($max <= 0) || ($smarty.foreach.heads.iteration < $max)}
        {assign var=headcommit value=$head->GetCommit()}
        <tr class="{cycle values="light,dark"}">
          <td><em>{$headcommit->GetAge()|agestring}</em></td>
          <td><a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=shortlog&amp;h=refs/heads/{$head->GetName()}" class="list"><strong>{$head->GetName()}</strong></a></td>
          <td class="link"><a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=shortlog&amp;h=refs/heads/{$head->GetName()}">{t}shortlog{/t}</a> | <a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=log&amp;h=refs/heads/{$head->GetName()}">{t}log{/t}</a> | <a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=tree&amp;hb={$headcommit->GetHash()}">{t}tree{/t}</a></td>
        </tr>
-     {/if}
    {/foreach}
+   {if $hasmoreheads}
+       <tr>
+       <td><a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=heads">&hellip;</a></td>
+       </tr>
+   {/if}
  </table>
 
 

--- a/templates/project.tpl
+++ b/templates/project.tpl
@@ -41,7 +41,7 @@
   
   {include file='title.tpl' target='tags'}
 
-  {include file='taglist.tpl' max=17}
+  {include file='taglist.tpl'}
    
  {/if}
 
@@ -49,7 +49,7 @@
 
   {include file='title.tpl' target='heads'}
 
-  {include file='headlist.tpl' max=17}
+  {include file='headlist.tpl'}
 
  {/if}
 

--- a/templates/taglist.tpl
+++ b/templates/taglist.tpl
@@ -12,9 +12,6 @@
  <table cellspacing="0" class="tagTable">
    {foreach from=$taglist item=tag name=tag}
      <tr class="{cycle name=tags values="light,dark"}">
-       {if ($max > 0) && ($smarty.foreach.tag.iteration == $max)}
-         <td><a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=tags">&hellip;</a></td>
-       {elseif ($max <= 0) || ($smarty.foreach.tag.iteration < $max)}
 	   {assign var=object value=$tag->GetObject()}
 	   {assign var=tagcommit value=$tag->GetCommit()}
 	   {assign var=objtype value=$tag->GetType()}
@@ -39,8 +36,12 @@
              <a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=commit&amp;h={$tagcommit->GetHash()}">{t}commit{/t}</a>
 	      | <a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=shortlog&amp;h={$tagcommit->GetHash()}">{t}shortlog{/t}</a> | <a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=log&amp;h={$tagcommit->GetHash()}">{t}log{/t}</a> | <a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=snapshot&amp;h={$tagcommit->GetHash()}" class="snapshotTip">{t}snapshot{/t}</a>
            </td>
-         {/if}
        </tr>
      {/foreach}
+     {if $hasmoretags}
+       <tr>
+         <td><a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=tags">&hellip;</a></td>
+       </tr>
+     {/if}
    </table>
 

comments