/** * Gets the data for a log * * @param GitPHP_Log $log log * @return string[] hash array */ public function Load($log) { if (!$log) { return; } return $this->RevList($log->GetProject(), $log->GetHeadHash(), $log->GetLimit(), $log->GetSkip()); }
/** * PopulateProjects * * Populates the internal list of projects * * @access protected * @throws Exception if file cannot be read */ protected function PopulateProjects() { $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot')); foreach ($this->projectConfig as $proj => $projData) { try { if (is_string($projData)) { // Just flat array of project paths $projObj = new GitPHP_Project($projectRoot, $projData); $this->projects[$projData] = $projObj; } else { if (is_array($projData)) { if (is_string($proj) && !empty($proj)) { // Project key pointing to data array $projObj = new GitPHP_Project($projectRoot, $proj); $this->projects[$proj] = $projObj; $this->ApplyProjectSettings($proj, $projData); } else { if (isset($projData['project'])) { // List of data arrays with projects inside $projObj = new GitPHP_Project($projectRoot, $projData['project']); $this->projects[$projData['project']] = $projObj; $this->ApplyProjectSettings(null, $projData); } } } } } catch (Exception $e) { GitPHP_Log::GetInstance()->Log($e->getMessage()); } } }
/** * PopulateProjects * * Populates the internal list of projects * * @access protected * @throws Exception if file cannot be read */ protected function PopulateProjects() { if (!($fp = fopen($this->projectConfig, 'r'))) { throw new Exception(sprintf(__('Failed to open project list file %1$s'), $this->projectConfig)); } $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot')); while (!feof($fp) && ($line = fgets($fp))) { if (preg_match('/^([^\\s]+)(\\s.+)?$/', $line, $regs)) { if (is_file($projectRoot . $regs[1] . '/HEAD')) { try { $projObj = new GitPHP_Project($projectRoot, $regs[1]); if (isset($regs[2]) && !empty($regs[2])) { $projOwner = trim($regs[2]); if (!empty($projOwner)) { $projObj->SetOwner($projOwner); } } $this->projects[$regs[1]] = $projObj; } catch (Exception $e) { GitPHP_Log::GetInstance()->Log($e->getMessage()); } } else { GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $projectRoot . $regs[1])); } } } fclose($fp); }
/** * GetInstance * * Returns the singleton instance * * @access public * @static * @return mixed instance of logging clas */ public static function GetInstance() { if (!self::$instance) { self::$instance = new GitPHP_Log(); } return self::$instance; }
/** * Loads data for this template */ protected function LoadData() { $log = GitPHP_DebugLog::GetInstance(); $log->TimerStart(); $head = $this->GetProject()->GetHeadCommit(); $this->tpl->assign('head', $head); if (!$head) { $this->tpl->assign('enablesearch', false); } $log->TimerStop('GetHeadCommit'); //$compat = $this->GetProject()->GetCompat(); $strategy = null; //if ($compat) { $strategy = new GitPHP_LogLoad_Git($this->exe); //} else { // $strategy = new GitPHP_LogLoad_Raw(); //} $revlist = new GitPHP_Log($this->GetProject(), $this->GetProject()->GetHeadCommit(), $strategy, 17); if ($revlist->GetCount() > 16) { $this->tpl->assign('hasmorerevs', true); $revlist->SetLimit(16); } $this->tpl->assign('revlist', $revlist); $log->TimerStart(); $taglist = $this->GetProject()->GetTagList()->GetOrderedTags('-creatordate', 17); $log->TimerStop('GetTagList'); if ($taglist) { if (count($taglist) > 16) { $this->tpl->assign('hasmoretags', true); $taglist = array_slice($taglist, 0, 16); } $this->tpl->assign('taglist', $taglist); } $log->TimerStart(); $headlist = $this->GetProject()->GetHeadList()->GetOrderedHeads('-committerdate', 17); $log->TimerStop('GetHeadList'); if ($headlist) { if (count($headlist) > 17) { $this->tpl->assign('hasmoreheads', true); $headlist = array_slice($headlist, 0, 16); } $this->tpl->assign('headlist', $headlist); } }
/** * Gets the data for a log * * @param GitPHP_Log $log log * @return string[] hash array */ public function Load($log) { if (!$log) { return; } $total = $log->GetLimit() + $log->GetSkip(); $head = $log->GetHead(); $inc = array(); $num = 0; $queue = array($head); while (($commit = array_shift($queue)) !== null) { $parents = $commit->GetParents(); foreach ($parents as $parent) { if (!isset($inc[$parent->GetHash()])) { $inc[$parent->GetHash()] = 1; $queue[] = $parent; $num++; } else { $inc[$parent->GetHash()]++; } } if ($num >= $total) { break; } } $queue = array($head); $commitLog = array(); $num = 0; while (($commit = array_pop($queue)) !== null) { array_push($commitLog, $commit); $num++; if ($num == $total) { break; } $parents = $commit->GetParents(); foreach ($parents as $parent) { if (isset($inc[$parent->GetHash()])) { if (--$inc[$parent->GetHash()] == 0) { $queue[] = $parent; } } } } if ($log->GetSkip() > 0) { $commitLog = array_slice($commitLog, $log->GetSkip(), $log->GetLimit()); } usort($commitLog, array('GitPHP_Commit', 'CompareAge')); $hashLog = array(); for ($i = 0; $i < count($commitLog); ++$i) { $hashLog[] = $commitLog[$i]->GetHash(); } return $hashLog; }
/** * Loads data for this template */ protected function LoadData() { $commit = $this->GetProject()->GetCommit($this->params['hash']); $this->tpl->assign('commit', $commit); $this->tpl->assign('head', $this->GetProject()->GetHeadCommit()); $this->tpl->assign('page', $this->params['page']); //$compat = $this->GetProject()->GetCompat(); $skip = $this->params['page'] * 100; $strategy = null; //if ($compat || ($skip > $this->config->GetValue('largeskip'))) { $strategy = new GitPHP_LogLoad_Git($this->exe); //} else { // $strategy = new GitPHP_LogLoad_Raw(); //} $revlist = new GitPHP_Log($this->GetProject(), $commit, $strategy, 101, $skip); if ($revlist->GetCount() > 100) { $this->tpl->assign('hasmorerevs', true); $revlist->SetLimit(100); } $this->tpl->assign('revlist', $revlist); if (isset($this->params['mark'])) { $this->tpl->assign('mark', $this->GetProject()->GetCommit($this->params['mark'])); } }
/** * PopulateProjects * * Populates the internal list of projects * * @access protected * @throws Exception if file cannot be read */ protected function PopulateProjects() { $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot')); foreach ($this->projectConfig as $cat => $plist) { if (is_array($plist)) { foreach ($plist as $pname => $ppath) { try { $projObj = new GitPHP_Project($projectRoot, $ppath); if ($cat != GITPHP_NO_CATEGORY) { $projObj->SetCategory($cat); } $this->projects[$ppath] = $projObj; } catch (Exception $e) { GitPHP_Log::GetInstance()->Log($e->getMessage()); } } } } }
/** * LoadHeaders * * Loads headers for this template * * @access protected */ protected function LoadHeaders() { if (isset($this->params['plain']) && $this->params['plain'] === true) { GitPHP_Log::GetInstance()->SetEnabled(false); $this->headers[] = 'Content-type: text/plain; charset=UTF-8'; } }
/** * PopulateProjects * * Populates the internal list of projects * * @access protected * @throws Exception if file cannot be read */ protected function PopulateProjects() { $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot')); $use_errors = libxml_use_internal_errors(true); $xml = simplexml_load_file($this->projectConfig); libxml_clear_errors(); libxml_use_internal_errors($use_errors); if (!$xml) { throw new Exception(sprintf('Could not load SCM manager config %1$s', $this->projectConfig)); } foreach ($xml->repositories->repository as $repository) { if ($repository->type != 'git') { GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $repository->name)); continue; } if ($repository->public != 'true') { GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not public', $repository->name)); continue; } $projName = trim($repository->name); if (empty($projName)) { continue; } if (is_file($projectRoot . $projName . '/HEAD')) { try { $projObj = new GitPHP_Project($projectRoot, $projName); $projOwner = trim($repository->contact); if (!empty($projOwner)) { $projObj->SetOwner($projOwner); } $projDesc = trim($repository->description); if (!empty($projDesc)) { $projObj->SetDescription($projDesc); } $this->projects[$projName] = $projObj; } catch (Exception $e) { GitPHP_Log::GetInstance()->Log($e->getMessage()); } } else { GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $projName)); } } }
/** * Execute * * Executes a command * * @param string $command the command to execute * @param array $args arguments * @return string result of command */ public function Execute($command, $args) { $fullCommand = $this->CreateCommand($command, $args); GitPHP_Log::GetInstance()->Log('Begin executing "' . $fullCommand . '"'); $ret = shell_exec($fullCommand); GitPHP_Log::GetInstance()->Log('Finish executing "' . $fullCommand . '"' . "\nwith result: " . $ret); return $ret; }
/** * ReadQuery * * Read query into parameters * * @access protected */ protected function ReadQuery() { if (isset($_GET['hb'])) { $this->params['hashbase'] = $_GET['hb']; } else { $this->params['hashbase'] = 'HEAD'; } if (isset($_GET['f'])) { $this->params['file'] = $_GET['f']; } if (isset($_GET['h'])) { $this->params['hash'] = $_GET['h']; } if (isset($_GET['o']) && $_GET['o'] == 'js') { $this->params['js'] = true; GitPHP_Log::GetInstance()->SetEnabled(false); } }
/** * ReadQuery * * Read query into parameters * * @access protected */ protected function ReadQuery() { if (isset($_GET['h'])) { $this->params['hash'] = $_GET['h']; } if (isset($_GET['o']) && $_GET['o'] == 'jstip') { $this->params['jstip'] = true; GitPHP_Log::GetInstance()->SetEnabled(false); } }
/** * ReadQuery * * Read query into parameters * * @access protected */ protected function ReadQuery() { GitPHP_Log::GetInstance()->SetEnabled(false); }
/** * LoadHeaders * * Loads headers for this template * * @access protected */ protected function LoadHeaders() { if (isset($this->params['plain']) && $this->params['plain']) { GitPHP_Log::GetInstance()->SetEnabled(false); $this->preserveWhitespace = true; // XXX: Nasty hack to cache headers if (!$this->tpl->isCached('blobheaders.tpl', $this->GetFullCacheKey())) { if (isset($this->params['file'])) { $saveas = $this->params['file']; } else { $saveas = $this->params['hash'] . ".txt"; } $headers = array(); $mime = null; if (GitPHP_Config::GetInstance()->GetValue('filemimetype', true)) { if (!isset($this->params['hash']) && isset($this->params['file'])) { $commit = $this->project->GetCommit($this->params['hashbase']); $this->params['hash'] = $commit->PathToHash($this->params['file']); } $blob = $this->project->GetBlob($this->params['hash']); $blob->SetPath($this->params['file']); $mime = $blob->FileMime(); } if ($mime) { $headers[] = "Content-type: " . $mime; } else { $headers[] = "Content-type: text/plain; charset=UTF-8"; } $headers[] = "Content-disposition: inline; filename=\"" . $saveas . "\""; $this->tpl->assign("blobheaders", serialize($headers)); } $out = $this->tpl->fetch('blobheaders.tpl', $this->GetFullCacheKey()); $this->headers = unserialize(trim($out)); } }
/** * LoadHeaders * * Loads headers for this template * * @access protected */ protected function LoadHeaders() { if (isset($this->params['opml']) && $this->params['opml'] === true) { $this->headers[] = "Content-type: text/xml; charset=UTF-8"; GitPHP_Log::GetInstance()->SetEnabled(false); $this->preserveWhitespace = true; } else { if (isset($this->params['txt']) && $this->params['txt'] === true) { $this->headers[] = "Content-type: text/plain; charset=utf-8"; $this->headers[] = "Content-Disposition: inline; filename=\"index.aux\""; GitPHP_Log::GetInstance()->SetEnabled(false); } } }
/** * ReadQuery * * Read query into parameters * * @access protected */ protected function ReadQuery() { if (isset($_GET['h'])) { $this->params['hash'] = $_GET['h']; } if (isset($_GET['f'])) { $this->params['path'] = $_GET['f']; } if (isset($_GET['prefix'])) { $this->params['prefix'] = $_GET['prefix']; } if (isset($_GET['fmt'])) { $this->params['format'] = $_GET['fmt']; } else { $this->params['format'] = GitPHP_Config::GetInstance()->GetValue('compressformat', GITPHP_COMPRESS_ZIP); } GitPHP_Log::GetInstance()->SetEnabled(false); }
$controller->Render(); } } catch (Exception $e) { if (GitPHP_Config::GetInstance()->GetValue('debug', false)) { throw $e; } if (!GitPHP_Resource::Instantiated()) { /* * In case an error was thrown before instantiating * the resource manager */ GitPHP_Resource::Instantiate('en_US'); } require_once GITPHP_CONTROLLERDIR . 'Controller_Message.class.php'; $controller = new GitPHP_Controller_Message(); $controller->SetParam('message', $e->getMessage()); if ($e instanceof GitPHP_MessageException) { $controller->SetParam('error', $e->Error); $controller->SetParam('statuscode', $e->StatusCode); } else { $controller->SetParam('error', true); } $controller->RenderHeaders(); $controller->Render(); } if (GitPHP_Log::GetInstance()->GetEnabled()) { $entries = GitPHP_Log::GetInstance()->GetEntries(); foreach ($entries as $logline) { echo "<br />\n" . $logline; } }
/** * AddProject * * Add project to collection * * @access private */ private function AddProject($projectPath) { try { $proj = new GitPHP_Project($this->projectDir, $projectPath); $category = trim(dirname($projectPath)); if (!(empty($category) || strpos($category, '.') === 0)) { $proj->SetCategory($category); } if (!GitPHP_Config::GetInstance()->GetValue('exportedonly', false) || $proj->GetDaemonEnabled()) { $this->projects[$projectPath] = $proj; } } catch (Exception $e) { GitPHP_Log::GetInstance()->Log($e->getMessage()); } }
/** * Loads data for this template */ protected function LoadData() { //$compat = $this->GetProject()->GetCompat(); $strategy = null; //if ($compat) { $strategy = new GitPHP_LogLoad_Git($this->exe); //} else { // $strategy = new GitPHP_LogLoad_Raw(); //} $log = new GitPHP_Log($this->GetProject(), $this->GetProject()->GetHeadCommit(), $strategy, GitPHP_Controller_Feed::FeedItemCount); if ($this->config->HasKey('feedfilter')) { $log->FilterCommits($this->config->GetValue('feedfilter')); } $log->FilterOldCommits(48 * 60 * 60, 20); $this->tpl->assign('log', $log); $this->tpl->assign('gitexe', $this->exe); }