/** * Loads sorted heads * * @param GitPHP_HeadList $headList head list * @param string $order list order * @param integer $count number to load * @param integer $skip number to skip */ public function LoadOrdered($headList, $order, $count = 0, $skip = 0) { if (!$headList) { return; } if (empty($order)) { return; } if (GitPHP_DebugLog::GetInstance()->GetEnabled()) { $autotimer = new GitPHP_DebugAutoLog(); } $heads = $headList->GetHeads(); /* TODO add different orders */ if ($order == '-committerdate') { @usort($heads, array('GitPHP_Head', 'CompareAge')); } if ($count > 0 && count($heads) > $count || $skip > 0) { if ($count > 0) { $heads = array_slice($heads, $skip, $count); } else { $heads = array_slice($heads, $skip); } } return $heads; }
/** * 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 raw content of an object * * @param string $hash object hash * @param int $type returns the object type * @return string object data */ public function GetObject($hash, &$type = 0) { if (!preg_match('/^[0-9A-Fa-f]{40}$/', $hash)) { return false; } if (GitPHP_DebugLog::GetInstance()->GetEnabled()) { $autolog = new GitPHP_DebugAutoLog(); } // first check if it's unpacked $path = $this->project->GetPath() . '/objects/' . substr($hash, 0, 2) . '/' . substr($hash, 2); if (file_exists($path)) { list($header, $data) = explode("", gzuncompress(file_get_contents($path)), 2); if (preg_match('/^([A-Za-z]+) /', $header, $typestr)) { switch ($typestr[1]) { case 'commit': $type = GitPHP_Pack::OBJ_COMMIT; break; case 'tree': $type = GitPHP_Pack::OBJ_TREE; break; case 'blob': $type = GitPHP_Pack::OBJ_BLOB; break; case 'tag': $type = GitPHP_Pack::OBJ_TAG; break; } } return $data; } if (!$this->packsRead) { $this->ReadPacks(); } // then try packs foreach ($this->packs as $pack) { $data = $pack->GetObject($hash, $type); if ($data !== false) { return $data; } } return false; }
/** * Loads the ref list for a ref type * * @param GitPHP_RefList $refList ref list * @param string $type ref type * @return array array of refs */ protected function GetRefs(GitPHP_RefList $refList, $type) { if (!$refList) { return; } if (empty($type)) { return; } if (GitPHP_DebugLog::GetInstance()->GetEnabled()) { $autotimer = new GitPHP_DebugAutoLog(); } $refs = array(); $prefix = 'refs/' . $type; $fullPath = $refList->GetProject()->GetPath() . '/' . $prefix; $fullPathLen = strlen($fullPath) + 1; /* loose files */ $refFiles = GitPHP_Util::ListDir($fullPath); for ($i = 0; $i < count($refFiles); ++$i) { $ref = substr($refFiles[$i], $fullPathLen); if (empty($ref) || isset($refs[$ref])) { continue; } $hash = trim(file_get_contents($refFiles[$i])); if (preg_match('/^[0-9A-Fa-f]{40}$/', $hash)) { $refs[$ref] = $hash; } } /* packed refs */ if (file_exists($refList->GetProject()->GetPath() . '/packed-refs')) { $packedRefs = explode("\n", file_get_contents($refList->GetProject()->GetPath() . '/packed-refs')); foreach ($packedRefs as $ref) { if (preg_match('/^([0-9A-Fa-f]{40}) refs\\/' . $type . '\\/(.+)$/', $ref, $regs)) { if (!isset($refs[$regs[2]])) { $refs[$regs[2]] = $regs[1]; } } } } return $refs; }
public function __destruct() { GitPHP_DebugLog::GetInstance()->TimerStop($this->name); }
/** * Renders the output */ public function Render() { if ($this->config->GetValue('cache') == true && $this->config->GetValue('cacheexpire') === true) { $this->CacheExpire(); } $log = GitPHP_DebugLog::GetInstance(); if (!$this->tpl->isCached($this->GetTemplate(), $this->GetFullCacheKey())) { $this->tpl->clearAllAssign(); $log->TimerStart(); $this->LoadCommonData(); $log->TimerStop('Common data'); $log->TimerStart(); $this->LoadData(); $log->TimerStop('Data'); } if (!$this->preserveWhitespace) { //$this->tpl->loadFilter('output', 'trimwhitespace'); } $log->TimerStart(); $this->tpl->display($this->GetTemplate(), $this->GetFullCacheKey()); $log->TimerStop('Render'); $this->tpl->clearAllAssign(); if ($this->projectList) { $log->Log('MemoryCache', 'Count: ' . $this->projectList->GetMemoryCache()->GetCount()); } if ($log->GetEnabled()) { $this->tpl->assign('debuglog', $log); $this->tpl->display('debug.tpl'); } }
protected function GetProcess($projectPath) { if (!$this->getProcessInitialized) { register_shutdown_function(array($this, 'DestroyAllProcesses')); $this->getProcessInitialized = true; } if (!isset(self::$processes[$projectPath])) { GitPHP_DebugLog::GetInstance()->TimerStart(); $process = proc_open($cmd = $this->CreateCommand($projectPath, GIT_CAT_FILE, array('--batch')), array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('file', GitPHP_Util::NullFile(), 'w')), $pipes); self::$processes[$projectPath] = array('process' => $process, 'pipes' => $pipes); GitPHP_DebugLog::GetInstance()->TimerStop('proc_open', $cmd); } return self::$processes[$projectPath]; }