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; }
/** * @see https://github.com/mojombo/grit/blob/master/lib/grit/git-ruby/internal/pack.rb */ protected function patchDelta($delta, RawObject $base_object) { $base = $base_object->getData(); list($src_size, $pos) = $this->patchDeltaHeaderSize($delta, 0); if ($src_size != strlen($base)) { throw new InvalidPackfileException("Packfile delta is invalid"); } list($dest_size, $pos) = $this->patchDeltaHeaderSize($delta, $pos); $dest = ""; while ($pos < strlen($delta)) { $c = ord($delta[$pos++]); if ($c & 0x80) { $cp_off = $cp_size = 0; if ($c & 0x1) { $cp_off = ord($delta[$pos++]); } if ($c & 0x2) { $cp_off |= ord($delta[$pos++]) << 8; } if ($c & 0x4) { $cp_off |= ord($delta[$pos++]) << 16; } if ($c & 0x8) { $cp_off |= ord($delta[$pos++]) << 24; } if ($c & 0x10) { $cp_size = ord($delta[$pos++]); } if ($c & 0x20) { $cp_size |= ord($delta[$pos++]) << 8; } if ($c & 0x40) { $cp_size |= ord($delta[$pos++]) << 16; } if ($cp_size == 0) { $cp_size = 0x10000; } $dest .= substr($base, $cp_off, $cp_size); } elseif ($c != 0) { $dest .= substr($delta, $pos, $c); $pos += $c; } else { throw new InvalidPackfileException("Packfile delta is invalid"); } } return $dest; }
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); } }