/** * PopulateProjects * * Populates the internal list of projects * * @access protected */ protected function PopulateProjects() { // HACK workaround for strange behavior of CACHING_LIFETIME_SAVED in smarty 3 $oldLifetime = GitPHP_Cache::GetObjectCacheInstance()->GetLifetime(); GitPHP_Cache::GetObjectCacheInstance()->SetLifetime(GitPHP_Config::GetInstance()->GetValue('cachelifetime', 3600)); $key = 'projectdir|' . $this->projectDir . '|projectlist|directory'; $cached = GitPHP_Cache::GetObjectCacheInstance()->Get($key); if ($cached && count($cached) > 0) { foreach ($cached as $proj) { $this->AddProject($proj); } GitPHP_Log::GetInstance()->Log('Loaded ' . count($this->projects) . ' projects from cache'); GitPHP_Cache::GetObjectCacheInstance()->SetLifetime($oldLifetime); return; } $this->RecurseDir($this->projectDir); if (count($this->projects) > 0) { $projects = array(); foreach ($this->projects as $proj) { $projects[] = $proj->GetProject(); } GitPHP_Cache::GetObjectCacheInstance()->Set($key, $projects, GitPHP_Config::GetInstance()->GetValue('cachelifetime', 3600)); } GitPHP_Cache::GetObjectCacheInstance()->SetLifetime($oldLifetime); }
/** * GetTree * * Gets a tree from this project * * @access public * @param string $hash tree hash */ public function GetTree($hash) { if (empty($hash)) { return null; } $cacheKey = 'project|' . $this->project . '|tree|' . $hash; $cached = GitPHP_Cache::GetObjectCacheInstance()->Get($cacheKey); if ($cached) { return $cached; } return new GitPHP_Tree($this, $hash); }
/** * ReadContents * * Reads the tree contents * * @access protected */ protected function ReadContents() { $this->contentsRead = true; if ($this->GetProject()->GetCompat()) { $this->ReadContentsGit(); } else { $this->ReadContentsRaw(); } GitPHP_Cache::GetObjectCacheInstance()->Set($this->GetCacheKey(), $this); }
/** * ReadCommit * * Attempts to dereference the commit for this tag * * @access private */ private function ReadCommit() { $exe = new GitPHP_GitExe($this->GetProject()); $args = array(); $args[] = '--tags'; $args[] = '--dereference'; $args[] = $this->refName; $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\\/tags\\/' . preg_quote($this->refName) . '(\\^{})$/', $line, $regs)) { $this->commit = $this->GetProject()->GetCommit($regs[1]); return; } } GitPHP_Cache::GetObjectCacheInstance()->Set($this->GetCacheKey(), $this); }
/** * ReadHashPaths * * Read hash to path mappings * * @access private */ private function ReadHashPaths() { $this->hashPathsRead = true; if ($this->GetProject()->GetCompat()) { $this->ReadHashPathsGit(); } else { $this->ReadHashPathsRaw($this->GetTree()); } GitPHP_Cache::GetObjectCacheInstance()->Set($this->GetCacheKey(), $this); }
/** * ReadData * * Reads the blob data * * @access private */ private function ReadData() { $this->dataRead = true; if ($this->GetProject()->GetCompat()) { $exe = new GitPHP_GitExe($this->GetProject()); $args = array(); $args[] = 'blob'; $args[] = $this->hash; $this->data = $exe->Execute(GIT_CAT_FILE, $args); } else { $this->data = $this->GetProject()->GetObject($this->hash); } GitPHP_Cache::GetObjectCacheInstance()->Set($this->GetCacheKey(), $this); }