/** * Initialize executable * * @param boolean $validate whether the exe should be validated */ protected function InitializeGitExe($validate = true) { $this->exe = new GitPHP_GitExe($this->config->GetValue('gitbin')); if ($this->log) { $this->exe->AddObserver($this->log); } if ($validate && !$this->exe->Valid()) { throw new GitPHP_InvalidGitExecutableException($this->exe->GetBinary()); } }
/** * Loads the history data */ protected function LoadData() { $this->dataLoaded = true; $args = array(); $args[] = $this->hash; $args[] = '--no-merges'; $canSkip = true; if ($this->skip > 0) { $canSkip = $this->exe->CanSkip(); } if ($canSkip) { if ($this->limit > 0) { $args[] = '--max-count=' . $this->limit; } if ($this->skip > 0) { $args[] = '--skip=' . $this->skip; } } else { if ($this->limit > 0) { $args[] = '--max-count=' . ($this->limit + $this->skip); } } $args[] = '--'; $args[] = $this->path; $args[] = '|'; $args[] = $this->exe->GetBinary(); $args[] = '--git-dir=' . escapeshellarg($this->project->GetPath()); $args[] = GIT_DIFF_TREE; $args[] = '-r'; $args[] = '--stdin'; $args[] = '--'; $args[] = $this->path; $historylines = explode("\n", $this->exe->Execute($this->project->GetPath(), GIT_REV_LIST, $args)); $commitHash = null; foreach ($historylines as $line) { if (preg_match('/^([0-9a-fA-F]{40})/', $line, $regs)) { $commitHash = $regs[1]; } else { if ($commitHash) { try { $this->history[] = array('diffline' => $line, 'commithash' => $commitHash); } catch (Exception $e) { } $commitHash = null; } } } if ($this->skip > 0 && !$canSkip) { if ($this->limit > 0) { $this->history = array_slice($this->history, $this->skip, $this->limit); } else { $this->history = array_slice($this->history, $this->skip); } } }
/* * Debug */ if (GitPHP_Log::GetInstance()->GetEnabled()) { GitPHP_Log::GetInstance()->SetStartTime(GITPHP_START_TIME); GitPHP_Log::GetInstance()->SetStartMemory(GITPHP_START_MEM); } if (!GitPHP_Config::GetInstance()->GetValue('projectroot', null)) { throw new GitPHP_MessageException(__('A projectroot must be set in the config'), true, 500); } /* * Check for required executables */ $exe = new GitPHP_GitExe(null); if (!$exe->Valid()) { throw new GitPHP_MessageException(sprintf(__('Could not run the git executable "%1$s". You may need to set the "%2$s" config value.'), $exe->GetBinary(), 'gitbin'), true, 500); } if (!function_exists('xdiff_string_diff')) { $exe = new GitPHP_DiffExe(); /* if (!$exe->Valid()) { throw new GitPHP_MessageException(sprintf(__('Could not run the diff executable "%1$s". You may need to set the "%2$s" config value.'), $exe->GetBinary(), 'diffbin'), true, 500); }*/ } unset($exe); /* * Authentification */ $auth = new GitPHP_Authentication(); $auth->authenticate(); /*
/** * ReadHistory * * Reads the file history * * @access private */ private function ReadHistory() { $this->historyRead = true; $exe = new GitPHP_GitExe($this->GetProject()); $args = array(); if (isset($this->commit)) { $args[] = $this->commit->GetHash(); } else { $args[] = 'HEAD'; } $args[] = '|'; $args[] = $exe->GetBinary(); $args[] = '--git-dir=' . $this->GetProject()->GetPath(); $args[] = GIT_DIFF_TREE; $args[] = '-r'; $args[] = '--stdin'; $args[] = '--'; $args[] = $this->GetPath(); $historylines = explode("\n", $exe->Execute(GIT_REV_LIST, $args)); $commit = null; foreach ($historylines as $line) { if (preg_match('/^([0-9a-fA-F]{40})/', $line, $regs)) { $commit = $this->GetProject()->GetCommit($regs[1]); } else { if ($commit) { try { $history = new GitPHP_FileDiff($this->GetProject(), $line); $history->SetCommit($commit); $this->history[] = $history; } catch (Exception $e) { } unset($commit); } } } }