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 desiccate(Commit $commit) { $writer = new StringWriter(); $this->writeTree($commit->getTree(), $writer); foreach ($commit->getParents() as $parent) { $this->writeParent($parent, $writer); } $this->writeAuthor($commit->getAuthor(), $commit->getAuthorTime(), $writer); $this->writeCommitter($commit->getCommitter(), $commit->getCommitTime(), $writer); $writer->writeString8("\n"); $writer->writeString8($commit->getMessage()); return new RawObject('commit', $writer->toString()); }
public function testCanCommitFromIndex() { $master = $this->repo->getObject('master'); $this->index_adapter->write('anotherfile.txt', 'Another day, another file'); $tree = $this->repo->getIndex()->createTree(); $commit = new Entity\GitObject\Commit(); $commit->setTree($tree); $commit->addParent($master); $commit->setMessage("Added another file"); $commit->setAuthor(new Entity\GitObject\User("Tessie Testson", "*****@*****.**")); $commit->setCommitter(new Entity\GitObject\User("Tessie Testson", "*****@*****.**")); $commit->setAuthorTime(new \DateTime()); $commit->setCommitTime(new \DateTime()); $this->repo->desiccateGitObject($commit); $this->repo->setBranch('master', $commit); $this->repo->flush(); $new_master_adapter = new GitternCommitishReadOnlyAdapter($this->repo, "master"); $this->assertEquals(array('Tech specs.pdf', 'anotherfile.txt', 'classic.txt', 'newfile.txt'), $new_master_adapter->keys()); $this->assertEquals('Another day, another file', $new_master_adapter->read('anotherfile.txt')); }