Project class is getting kind of big, reorganize a bit with code folds
--- a/include/git/Project.class.php
+++ b/include/git/Project.class.php
@@ -25,6 +25,8 @@
class GitPHP_Project
{
+/* internal variables {{{1*/
+
/**
* projectRoot
*
@@ -43,6 +45,8 @@
*/
protected $project;
+/* owner internal variables {{{2*/
+
/**
* owner
*
@@ -60,6 +64,10 @@
* @access protected
*/
protected $ownerRead = false;
+
+/*}}}2*/
+
+/* description internal variables {{{2*/
/**
* description
@@ -80,6 +88,8 @@
*/
protected $readDescription = false;
+/*}}}2*/
+
/**
* category
*
@@ -89,6 +99,8 @@
*/
protected $category = '';
+/* epoch internal variables {{{2*/
+
/**
* epoch
*
@@ -107,6 +119,10 @@
*/
protected $epochRead = false;
+/*}}}2*/
+
+/* HEAD internal variables {{{2*/
+
/**
* head
*
@@ -125,6 +141,10 @@
*/
protected $readHeadRef = false;
+/*}}}*/
+
+/* ref internal variables {{{2*/
+
/**
* tags
*
@@ -152,6 +172,10 @@
*/
protected $readRefs = false;
+/*}}}2*/
+
+/* url internal variables {{{2*/
+
/**
* cloneUrl
*
@@ -170,6 +194,10 @@
*/
protected $pushUrl = null;
+/*}}}2*/
+
+/* bugtracker internal variables {{{2*/
+
/**
* bugUrl
*
@@ -187,6 +215,8 @@
* @access protected
*/
protected $bugPattern = null;
+
+/*}}}2*/
/**
* commitCache
@@ -198,6 +228,8 @@
*/
protected $commitCache = array();
+/* packfile internal variables {{{2*/
+
/**
* packs
*
@@ -215,6 +247,12 @@
* @access protected
*/
protected $packsRead = false;
+
+/*}}}2*/
+
+/*}}}1*/
+
+/* class methods {{{1*/
/**
* __construct
@@ -232,6 +270,25 @@
$this->SetProject($project);
}
+/*}}}1*/
+
+/* accessors {{{1*/
+
+/* project accessors {{{2*/
+
+ /**
+ * GetProject
+ *
+ * Gets the project
+ *
+ * @access public
+ * @return string the project
+ */
+ public function GetProject()
+ {
+ return $this->project;
+ }
+
/**
* SetProject
*
@@ -267,6 +324,41 @@
$this->project = $project;
}
+
+/*}}}2*/
+
+ /**
+ * GetSlug
+ *
+ * Gets the project as a filename/url friendly slug
+ *
+ * @access public
+ * @return string the slug
+ */
+ public function GetSlug()
+ {
+ $project = $this->project;
+
+ if (substr($project, -4) == '.git')
+ $project = substr($project, 0, -4);
+
+ return GitPHP_Util::MakeSlug($project);
+ }
+
+ /**
+ * GetPath
+ *
+ * Gets the full project path
+ *
+ * @access public
+ * @return string project path
+ */
+ public function GetPath()
+ {
+ return $this->projectRoot . $this->project;
+ }
+
+/* owner accessors {{{2 */
/**
* GetOwner
@@ -385,18 +477,9 @@
$this->owner = $owner;
}
- /**
- * GetProject
- *
- * Gets the project
- *
- * @access public
- * @return string the project
- */
- public function GetProject()
- {
- return $this->project;
- }
+/*}}}2*/
+
+/* projectroot accessors {{{2*/
/**
* GetProjectRoot
@@ -411,36 +494,9 @@
return $this->projectRoot;
}
- /**
- * GetSlug
- *
- * Gets the project as a filename/url friendly slug
- *
- * @access public
- * @return string the slug
- */
- public function GetSlug()
- {
- $project = $this->project;
-
- if (substr($project, -4) == '.git')
- $project = substr($project, 0, -4);
-
- return GitPHP_Util::MakeSlug($project);
- }
-
- /**
- * GetPath
- *
- * Gets the full project path
- *
- * @access public
- * @return string project path
- */
- public function GetPath()
- {
- return $this->projectRoot . $this->project;
- }
+/*}}}2*/
+
+/* description accessors {{{2*/
/**
* GetDescription
@@ -481,6 +537,8 @@
$this->readDescription = true;
}
+/*}}}2*/
+
/**
* GetDaemonEnabled
*
@@ -493,6 +551,8 @@
{
return file_exists($this->GetPath() . '/git-daemon-export-ok');
}
+
+/* category accessors {{{2*/
/**
* GetCategory
@@ -520,6 +580,10 @@
$this->category = $category;
}
+/*}}}2*/
+
+/* clone url accessors {{{2*/
+
/**
* GetCloneUrl
*
@@ -553,6 +617,10 @@
$this->cloneUrl = $cUrl;
}
+/*}}}2*/
+
+/* push url accessors {{{2*/
+
/**
* GetPushUrl
*
@@ -586,6 +654,10 @@
$this->pushUrl = $pUrl;
}
+/*}}}2*/
+
+/* bugtracker accessors {{{2*/
+
/**
* GetBugUrl
*
@@ -643,6 +715,10 @@
{
$this->bugPattern = $bPat;
}
+
+/*}}}2*/
+
+/* HEAD accessors {{{2*/
/**
* GetHeadCommit
@@ -718,6 +794,123 @@
}
}
}
+
+/*}}}2*/
+
+/* epoch accessors {{{2*/
+
+ /**
+ * GetEpoch
+ *
+ * Gets this project's epoch
+ * (time of last change)
+ *
+ * @access public
+ * @return integer timestamp
+ */
+ public function GetEpoch()
+ {
+ if (!$this->epochRead)
+ $this->ReadEpoch();
+
+ return $this->epoch;
+ }
+
+ /**
+ * GetAge
+ *
+ * Gets this project's age
+ * (time since most recent change)
+ *
+ * @access public
+ * @return integer age
+ */
+ public function GetAge()
+ {
+ if (!$this->epochRead)
+ $this->ReadEpoch();
+
+ return time() - $this->epoch;
+ }
+
+ /**
+ * ReadEpoch
+ *
+ * Reads this project's epoch
+ * (timestamp of most recent change)
+ *
+ * @access private
+ */
+ private function ReadEpoch()
+ {
+ $this->epochRead = true;
+
+ if (GitPHP_Config::GetInstance()->GetValue('compat', false)) {
+ $this->ReadEpochGit();
+ } else {
+ $this->ReadEpochRaw();
+ }
+ }
+
+ /**
+ * ReadEpochGit
+ *
+ * Reads this project's epoch using git executable
+ *
+ * @access private
+ */
+ private function ReadEpochGit()
+ {
+ $exe = new GitPHP_GitExe($this);
+
+ $args = array();
+ $args[] = '--format="%(committer)"';
+ $args[] = '--sort=-committerdate';
+ $args[] = '--count=1';
+ $args[] = 'refs/heads';
+
+ $epochstr = trim($exe->Execute(GIT_FOR_EACH_REF, $args));
+
+ if (preg_match('/ (\d+) [-+][01]\d\d\d$/', $epochstr, $regs)) {
+ $this->epoch = $regs[1];
+ }
+
+ unset($exe);
+ }
+
+ /**
+ * ReadEpochRaw
+ *
+ * Reads this project's epoch using raw objects
+ *
+ * @access private
+ */
+ private function ReadEpochRaw()
+ {
+ if (!$this->readRefs)
+ $this->ReadRefList();
+
+ $epoch = 0;
+ foreach ($this->heads as $head) {
+ $commit = $head->GetCommit();
+ if ($commit) {
+ if ($commit->GetCommitterEpoch() > $epoch) {
+ $epoch = $commit->GetCommitterEpoch();
+ }
+ }
+ }
+ if ($epoch > 0) {
+ $this->epoch = $epoch;
+ }
+ }
+
+/*}}}2*/
+
+/*}}}1*/
+
+/* data loading methods {{{1*/
+
+/* commit loading methods {{{2*/
/**
* GetCommit
@@ -777,87 +970,9 @@
return null;
}
- /**
- * CompareProject
- *
- * Compares two projects by project name
- *
- * @access public
- * @static
- * @param mixed $a first project
- * @param mixed $b second project
- * @return integer comparison result
- */
- public static function CompareProject($a, $b)
- {
- $catCmp = strcmp($a->GetCategory(), $b->GetCategory());
- if ($catCmp !== 0)
- return $catCmp;
-
- return strcmp($a->GetProject(), $b->GetProject());
- }
-
- /**
- * CompareDescription
- *
- * Compares two projects by description
- *
- * @access public
- * @static
- * @param mixed $a first project
- * @param mixed $b second project
- * @return integer comparison result
- */
- public static function CompareDescription($a, $b)
- {
- $catCmp = strcmp($a->GetCategory(), $b->GetCategory());
- if ($catCmp !== 0)
- return $catCmp;
-
- return strcmp($a->GetDescription(), $b->GetDescription());
- }
-
- /**
- * CompareOwner
- *
- * Compares two projects by owner
- *
- * @access public
- * @static
- * @param mixed $a first project
- * @param mixed $b second project
- * @return integer comparison result
- */
- public static function CompareOwner($a, $b)
- {
- $catCmp = strcmp($a->GetCategory(), $b->GetCategory());
- if ($catCmp !== 0)
- return $catCmp;
-
- return strcmp($a->GetOwner(), $b->GetOwner());
- }
-
- /**
- * CompareAge
- *
- * Compares two projects by age
- *
- * @access public
- * @static
- * @param mixed $a first project
- * @param mixed $b second project
- * @return integer comparison result
- */
- public static function CompareAge($a, $b)
- {
- $catCmp = strcmp($a->GetCategory(), $b->GetCategory());
- if ($catCmp !== 0)
- return $catCmp;
-
- if ($a->GetAge() === $b->GetAge())
- return 0;
- return ($a->GetAge() < $b->GetAge() ? -1 : 1);
- }
+/*}}}2*/
+
+/* ref loading methods {{{2*/
/**
* GetRefs
@@ -1053,6 +1168,10 @@
return $files;
}
+/*}}}2*/
+
+/* tag loading methods {{{2*/
+
/**
* GetTags
*
@@ -1180,6 +1299,10 @@
}
}
+/*}}}2*/
+
+/* head loading methods {{{2*/
+
/**
* GetHeads
*
@@ -1282,6 +1405,10 @@
return $this->heads[$key];
}
+
+/*}}}2*/
+
+/* log methods {{{2*/
/**
* GetLogHash
@@ -1396,6 +1523,10 @@
return $log;
}
+/*}}}2*/
+
+/* blob loading methods {{{2*/
+
/**
* GetBlob
*
@@ -1417,6 +1548,10 @@
return new GitPHP_Blob($this, $hash);
}
+/*}}}2*/
+
+/* tree loading methods {{{2*/
+
/**
* GetTree
*
@@ -1438,264 +1573,9 @@
return new GitPHP_Tree($this, $hash);
}
- /**
- * SearchCommit
- *
- * Gets a list of commits with commit messages matching the given pattern
- *
- * @access public
- * @param string $pattern search pattern
- * @param string $hash hash to start searching from
- * @param integer $count number of results to get
- * @param integer $skip number of results to skip
- * @return array array of matching commits
- */
- public function SearchCommit($pattern, $hash = 'HEAD', $count = 50, $skip = 0)
- {
- if (empty($pattern))
- return;
-
- $args = array();
-
- $exe = new GitPHP_GitExe($this);
- if ($exe->CanIgnoreRegexpCase())
- $args[] = '--regexp-ignore-case';
- unset($exe);
-
- $args[] = '--grep=\'' . $pattern . '\'';
-
- $ret = $this->RevList($hash, $count, $skip, $args);
- $len = count($ret);
-
- for ($i = 0; $i < $len; ++$i) {
- $ret[$i] = $this->GetCommit($ret[$i]);
- }
- return $ret;
- }
-
- /**
- * SearchAuthor
- *
- * Gets a list of commits with authors matching the given pattern
- *
- * @access public
- * @param string $pattern search pattern
- * @param string $hash hash to start searching from
- * @param integer $count number of results to get
- * @param integer $skip number of results to skip
- * @return array array of matching commits
- */
- public function SearchAuthor($pattern, $hash = 'HEAD', $count = 50, $skip = 0)
- {
- if (empty($pattern))
- return;
-
- $args = array();
-
- $exe = new GitPHP_GitExe($this);
- if ($exe->CanIgnoreRegexpCase())
- $args[] = '--regexp-ignore-case';
- unset($exe);
-
- $args[] = '--author=\'' . $pattern . '\'';
-
- $ret = $this->RevList($hash, $count, $skip, $args);
- $len = count($ret);
-
- for ($i = 0; $i < $len; ++$i) {
- $ret[$i] = $this->GetCommit($ret[$i]);
- }
- return $ret;
- }
-
- /**
- * SearchCommitter
- *
- * Gets a list of commits with committers matching the given pattern
- *
- * @access public
- * @param string $pattern search pattern
- * @param string $hash hash to start searching from
- * @param integer $count number of results to get
- * @param integer $skip number of results to skip
- * @return array array of matching commits
- */
- public function SearchCommitter($pattern, $hash = 'HEAD', $count = 50, $skip = 0)
- {
- if (empty($pattern))
- return;
-
- $args = array();
-
- $exe = new GitPHP_GitExe($this);
- if ($exe->CanIgnoreRegexpCase())
- $args[] = '--regexp-ignore-case';
- unset($exe);
-
- $args[] = '--committer=\'' . $pattern . '\'';
-
- $ret = $this->RevList($hash, $count, $skip, $args);
- $len = count($ret);
-
- for ($i = 0; $i < $len; ++$i) {
- $ret[$i] = $this->GetCommit($ret[$i]);
- }
- return $ret;
- }
-
- /**
- * RevList
- *
- * Common code for using rev-list command
- *
- * @access private
- * @param string $hash hash to list from
- * @param integer $count number of results to get
- * @param integer $skip number of results to skip
- * @param array $args args to give to rev-list
- * @return array array of hashes
- */
- private function RevList($hash, $count = 50, $skip = 0, $args = array())
- {
- if ($count < 1)
- return;
-
- $exe = new GitPHP_GitExe($this);
-
- $canSkip = true;
-
- if ($skip > 0)
- $canSkip = $exe->CanSkip();
-
- if ($canSkip) {
- $args[] = '--max-count=' . $count;
- if ($skip > 0) {
- $args[] = '--skip=' . $skip;
- }
- } else {
- $args[] = '--max-count=' . ($count + $skip);
- }
-
- $args[] = $hash;
-
- $revlist = explode("\n", $exe->Execute(GIT_REV_LIST, $args));
-
- if (!$revlist[count($revlist)-1]) {
- /* the last newline creates a null entry */
- array_splice($revlist, -1, 1);
- }
-
- if (($skip > 0) && (!$exe->CanSkip())) {
- return array_slice($revlist, $skip, $count);
- }
-
- return $revlist;
- }
-
- /**
- * GetEpoch
- *
- * Gets this project's epoch
- * (time of last change)
- *
- * @access public
- * @return integer timestamp
- */
- public function GetEpoch()
- {
- if (!$this->epochRead)
- $this->ReadEpoch();
-
- return $this->epoch;
- }
-
- /**
- * GetAge
- *
- * Gets this project's age
- * (time since most recent change)
- *
- * @access public
- * @return integer age
- */
- public function GetAge()
- {
- if (!$this->epochRead)
- $this->ReadEpoch();
-
- return time() - $this->epoch;
- }
-
- /**
- * ReadEpoch
- *
- * Reads this project's epoch
- * (timestamp of most recent change)
- *
- * @access private
- */
- private function ReadEpoch()
- {
- $this->epochRead = true;
-
- if (GitPHP_Config::GetInstance()->GetValue('compat', false)) {
- $this->ReadEpochGit();
- } else {
- $this->ReadEpochRaw();
- }
- }
-
- /**
- * ReadEpochGit
- *
- * Reads this project's epoch using git executable
- *
- * @access private
- */
- private function ReadEpochGit()
- {
- $exe = new GitPHP_GitExe($this);
-
- $args = array();
- $args[] = '--format="%(committer)"';
- $args[] = '--sort=-committerdate';
- $args[] = '--count=1';
- $args[] = 'refs/heads';
-
- $epochstr = trim($exe->Execute(GIT_FOR_EACH_REF, $args));
-
- if (preg_match('/ (\d+) [-+][01]\d\d\d$/', $epochstr, $regs)) {
- $this->epoch = $regs[1];
- }
-
- unset($exe);
- }
-
- /**
- * ReadEpochRaw
- *
- * Reads this project's epoch using raw objects
- *
- * @access private
- */
- private function ReadEpochRaw()
- {
- if (!$this->readRefs)
- $this->ReadRefList();
-
- $epoch = 0;
- foreach ($this->heads as $head) {
- $commit = $head->GetCommit();
- if ($commit) {
- if ($commit->GetCommitterEpoch() > $epoch) {
- $epoch = $commit->GetCommitterEpoch();
- }
- }
- }
- if ($epoch > 0) {
- $this->epoch = $epoch;
- }
- }
+/*}}}2*/
+
+/* raw object loading methods {{{2*/
/**
* GetObject
@@ -1769,5 +1649,257 @@
$this->packsRead = true;
}
+/*}}}2*/
+
+/*}}}1*/
+
+/* search methods {{{1*/
+
+ /**
+ * SearchCommit
+ *
+ * Gets a list of commits with commit messages matching the given pattern
+ *
+ * @access public
+ * @param string $pattern search pattern
+ * @param string $hash hash to start searching from
+ * @param integer $count number of results to get
+ * @param integer $skip number of results to skip
+ * @return array array of matching commits
+ */
+ public function SearchCommit($pattern, $hash = 'HEAD', $count = 50, $skip = 0)
+ {
+ if (empty($pattern))
+ return;
+
+ $args = array();
+
+ $exe = new GitPHP_GitExe($this);
+ if ($exe->CanIgnoreRegexpCase())
+ $args[] = '--regexp-ignore-case';
+ unset($exe);
+
+ $args[] = '--grep=\'' . $pattern . '\'';
+
+ $ret = $this->RevList($hash, $count, $skip, $args);
+ $len = count($ret);
+
+ for ($i = 0; $i < $len; ++$i) {
+ $ret[$i] = $this->GetCommit($ret[$i]);
+ }
+ return $ret;
+ }
+
+ /**
+ * SearchAuthor
+ *
+ * Gets a list of commits with authors matching the given pattern
+ *
+ * @access public
+ * @param string $pattern search pattern
+ * @param string $hash hash to start searching from
+ * @param integer $count number of results to get
+ * @param integer $skip number of results to skip
+ * @return array array of matching commits
+ */
+ public function SearchAuthor($pattern, $hash = 'HEAD', $count = 50, $skip = 0)
+ {
+ if (empty($pattern))
+ return;
+
+ $args = array();
+
+ $exe = new GitPHP_GitExe($this);
+ if ($exe->CanIgnoreRegexpCase())
+ $args[] = '--regexp-ignore-case';
+ unset($exe);
+
+ $args[] = '--author=\'' . $pattern . '\'';
+
+ $ret = $this->RevList($hash, $count, $skip, $args);
+ $len = count($ret);
+
+ for ($i = 0; $i < $len; ++$i) {
+ $ret[$i] = $this->GetCommit($ret[$i]);
+ }
+ return $ret;
+ }
+
+ /**
+ * SearchCommitter
+ *
+ * Gets a list of commits with committers matching the given pattern
+ *
+ * @access public
+ * @param string $pattern search pattern
+ * @param string $hash hash to start searching from
+ * @param integer $count number of results to get
+ * @param integer $skip number of results to skip
+ * @return array array of matching commits
+ */
+ public function SearchCommitter($pattern, $hash = 'HEAD', $count = 50, $skip = 0)
+ {
+ if (empty($pattern))
+ return;
+
+ $args = array();
+
+ $exe = new GitPHP_GitExe($this);
+ if ($exe->CanIgnoreRegexpCase())
+ $args[] = '--regexp-ignore-case';
+ unset($exe);
+
+ $args[] = '--committer=\'' . $pattern . '\'';
+
+ $ret = $this->RevList($hash, $count, $skip, $args);
+ $len = count($ret);
+
+ for ($i = 0; $i < $len; ++$i) {
+ $ret[$i] = $this->GetCommit($ret[$i]);
+ }
+ return $ret;
+ }
+
+/*}}}1*/
+
+/* private utilities {{{1*/
+
+ /**
+ * RevList
+ *
+ * Common code for using rev-list command
+ *
+ * @access private
+ * @param string $hash hash to list from
+ * @param integer $count number of results to get
+ * @param integer $skip number of results to skip
+ * @param array $args args to give to rev-list
+ * @return array array of hashes
+ */
+ private function RevList($hash, $count = 50, $skip = 0, $args = array())
+ {
+ if ($count < 1)
+ return;
+
+ $exe = new GitPHP_GitExe($this);
+
+ $canSkip = true;
+
+ if ($skip > 0)
+ $canSkip = $exe->CanSkip();
+
+ if ($canSkip) {
+ $args[] = '--max-count=' . $count;
+ if ($skip > 0) {
+ $args[] = '--skip=' . $skip;
+ }
+ } else {
+ $args[] = '--max-count=' . ($count + $skip);
+ }
+
+ $args[] = $hash;
+
+ $revlist = explode("\n", $exe->Execute(GIT_REV_LIST, $args));
+
+ if (!$revlist[count($revlist)-1]) {
+ /* the last newline creates a null entry */
+ array_splice($revlist, -1, 1);
+ }
+
+ if (($skip > 0) && (!$exe->CanSkip())) {
+ return array_slice($revlist, $skip, $count);
+ }
+
+ return $revlist;
+ }
+
+/*}}}1*/
+
+/* static utilities {{{1*/
+
+ /**
+ * CompareProject
+ *
+ * Compares two projects by project name
+ *
+ * @access public
+ * @static
+ * @param mixed $a first project
+ * @param mixed $b second project
+ * @return integer comparison result
+ */
+ public static function CompareProject($a, $b)
+ {
+ $catCmp = strcmp($a->GetCategory(), $b->GetCategory());
+ if ($catCmp !== 0)
+ return $catCmp;
+
+ return strcmp($a->GetProject(), $b->GetProject());
+ }
+
+ /**
+ * CompareDescription
+ *
+ * Compares two projects by description
+ *
+ * @access public
+ * @static
+ * @param mixed $a first project
+ * @param mixed $b second project
+ * @return integer comparison result
+ */
+ public static function CompareDescription($a, $b)
+ {
+ $catCmp = strcmp($a->GetCategory(), $b->GetCategory());
+ if ($catCmp !== 0)
+ return $catCmp;
+
+ return strcmp($a->GetDescription(), $b->GetDescription());
+ }
+
+ /**
+ * CompareOwner
+ *
+ * Compares two projects by owner
+ *
+ * @access public
+ * @static
+ * @param mixed $a first project
+ * @param mixed $b second project
+ * @return integer comparison result
+ */
+ public static function CompareOwner($a, $b)
+ {
+ $catCmp = strcmp($a->GetCategory(), $b->GetCategory());
+ if ($catCmp !== 0)
+ return $catCmp;
+
+ return strcmp($a->GetOwner(), $b->GetOwner());
+ }
+
+ /**
+ * CompareAge
+ *
+ * Compares two projects by age
+ *
+ * @access public
+ * @static
+ * @param mixed $a first project
+ * @param mixed $b second project
+ * @return integer comparison result
+ */
+ public static function CompareAge($a, $b)
+ {
+ $catCmp = strcmp($a->GetCategory(), $b->GetCategory());
+ if ($catCmp !== 0)
+ return $catCmp;
+
+ if ($a->GetAge() === $b->GetAge())
+ return 0;
+ return ($a->GetAge() < $b->GetAge() ? -1 : 1);
+ }
+
+/*}}}1*/
+
}