/** * Gets a file diff * * @param string $fromHash source hash, can also be a diff-tree info line * @param string $toHash target hash, required if $fromHash is a hash * @return GitPHP_FileDiff file diff object */ public function GetFileDiff($fromHash, $toHash = '') { if (preg_match('/^[0-9A-Fa-f]{4,39}$/', $fromHash) && !$this->compat) { $fullHash = $this->project->ExpandHash($fromHash); if ($fullHash == $fromHash) { throw new GitPHP_InvalidHashException($fromHash); } $fromHash = $fullHash; } if (!empty($toHash) && preg_match('/^[0-9A-Fa-f]{4,39}$/', $toHash) && !$this->compat) { $fullHash = $this->project->ExpandHash($toHash); if ($fullHash == $toHash) { throw new GitPHP_InvalidHashException($toHash); } $toHash = $fullHash; } $fileDiff = new GitPHP_FileDiff($this->project, $fromHash, $toHash); $fileDiff->SetCache($this->cache); return $fileDiff; }
/** * 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); } } } }