/** * Parse a single line into pieces * * @param string $line a single line output from the git binary * * @return mixed */ private function parseLine($line) { if ($line == '') { return; } $slices = Object::getLineSlices($line); if ($this->isBlob()) { $this->pathChildren[] = $this->blob->getName(); } else { if ($this->isRoot()) { // if is root check for first children $pattern = '/(\\w+)\\/(.*)/'; $replacement = '$1'; } else { // filter by the children of the path $actualPath = $this->subject->getFullPath(); if (!preg_match(sprintf('/^%s\\/(\\w*)/', preg_quote($actualPath, '/')), $slices['fullPath'])) { return; } $pattern = sprintf('/^%s\\/(\\w*)/', preg_quote($actualPath, '/')); $replacement = '$1'; } $name = preg_replace($pattern, $replacement, $slices['fullPath']); if (strpos($name, '/') !== false) { return; } if (!in_array($name, $this->pathChildren)) { $path = rtrim(rtrim($slices['fullPath'], $name), '/'); $treeObject = new TreeObject($this->repository, $slices['permissions'], $slices['type'], $slices['sha'], $slices['size'], $name, $path); $this->children[] = $treeObject; $this->pathChildren[] = $name; } } }