Author: Magnus Nordlander
Inheritance: implements IteratorAggregate
Esempio n. 1
0
 protected function writeTree(Tree $tree, Writer $writer)
 {
     $sha = $tree->getSha();
     if (strlen($sha) != 40) {
         throw new NotPersistedException("Tree referred to by commit is not persisted yet.");
     }
     $writer->writeString8("tree ");
     $writer->writeString8($sha);
     $writer->writeString8("\n");
 }
Esempio n. 2
0
 public function desiccate(Tree $tree)
 {
     $writer = new StringWriter();
     foreach ($tree->getNodes() as $node) {
         $writer->writeString8($node->getOctalModeString());
         $writer->writeString8(' ');
         $writer->writeString8($node->getName());
         $writer->writeString8("");
         $sha = $node->getRelatedObject()->getSha();
         if (strlen($sha) != 40) {
             throw new NotPersistedException("Object referred to by node named " . $node->getName() . " is not persisted yet.");
         }
         $writer->writeHHex($sha);
     }
     $data = $writer->toString();
     return new RawObject('tree', $data);
 }
Esempio n. 3
0
 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;
 }