/** * Gets the matching object * * @return GitPHP_Tree|GitPHP_Blob|null matching object */ public function GetObject() { if ($this->objectType == 'tree') { $tree = $this->project->GetObjectManager()->GetTree($this->objectHash); $tree->SetPath($this->path); return $tree; } else { if ($this->objectType == 'blob') { $blob = $this->project->GetObjectManager()->GetBlob($this->objectHash); $blob->SetPath($this->path); return $blob; } } return null; }
/** * Searches file contents for matches */ private function SearchFileContents() { $args = array(); $args[] = '-I'; $args[] = '--full-name'; $args[] = '--ignore-case'; $args[] = '-n'; $args[] = '-e'; $args[] = '"' . addslashes($this->search) . '"'; $args[] = $this->treeHash; $lines = explode("\n", $this->exe->Execute($this->project->GetPath(), GIT_GREP, $args)); foreach ($lines as $line) { if (preg_match('/^[^:]+:([^:]+):([0-9]+):(.+)$/', $line, $regs)) { if (isset($this->allResults[$regs[1]])) { $result = $this->allResults[$regs[1]]; $matchingLines = $result->GetMatchingLines(); $matchingLines[(int) $regs[2]] = trim($regs[3], "\n\r\v"); $result->SetMatchingLines($matchingLines); } else { $tree = $this->GetTree(); $hash = $tree->PathToHash($regs[1]); if ($hash) { $blob = $this->project->GetObjectManager()->GetBlob($hash); $blob->SetPath($regs[1]); $result = new GitPHP_FileSearchResult($this->project, $blob, $regs[1]); $matchingLines = array(); $matchingLines[(int) $regs[2]] = trim($regs[3], "\n\r\v"); $result->SetMatchingLines($matchingLines); $this->allResults[$regs[1]] = $result; } } } } }