public function hydrate(RawObject $raw_object) { $commit = new Commit(); $commit->setSha($raw_object->getSha()); list($meta, $message) = explode("\n\n", $raw_object->getData()); $commit->setMessage($message); foreach (explode("\n", $meta) as $meta_line) { sscanf($meta_line, "%s ", $attribute); $attribute_value = substr($meta_line, strlen($attribute) + 1); switch ($attribute) { case 'tree': $commit->setTree(new TreeProxy($this->repo, $attribute_value)); break; case 'parent': $commit->addParent(new CommitProxy($this->repo, $attribute_value)); break; case 'author': preg_match('/(.*?) <(.*?)> ([0-9]*)( (.+))?/', $attribute_value, $matches); $commit->setAuthor(new User($matches[1], $matches[2])); $commit->setAuthorTime(\DateTime::createFromFormat('U O', $matches[3] . ' ' . $matches[5])); break; case 'committer': preg_match('/(.*?) <(.*?)> ([0-9]*)( (.+))?/', $attribute_value, $matches); $commit->setCommitter(new User($matches[1], $matches[2])); $commit->setCommitTime(\DateTime::createFromFormat('U O', $matches[3] . ' ' . $matches[5])); break; } } return $commit; }
public function hydrate(RawObject $raw_object) { $blob = new Blob(); $blob->setSha($raw_object->getSha()); $blob->setContents($raw_object->getData()); return $blob; }
public function hydrate(RawObject $raw_object) { $tree = new Tree(); $tree->setSha($raw_object->getSha()); $reader = new StringReader($raw_object->getData()); while ($reader->available()) { $mode = intval($this->readModeString($reader), 8); $name = $this->readName($reader); $sha = $reader->readHHex(20); $is_tree = (bool) ($mode & 040000); if ($is_tree) { $node = new Node\TreeNode(); $node->setTree(new TreeProxy($this->repo, $sha)); } else { $node = new Node\BlobNode(); $node->setBlob(new BlobProxy($this->repo, $sha)); } $node->setIntegerMode($mode); $node->setName($name); $tree->addNode($node); } return $tree; }
public function putRawObject(RawObject $raw_object) { $sha = $raw_object->getSha(); $first = substr($sha, 0, 2); $last = substr($sha, 2); $data = gzcompress($raw_object->getType() . ' ' . $raw_object->getLength() . "" . $raw_object->getData(), 4); if (!$this->isFileRelative('objects/' . $first . '/' . $last)) { $this->writeFileRelative('objects/' . $first . '/' . $last, $data); } }