function git_read_tag($proj, $tag_id) { $obj = $proj->getObject($tag_id); if ($obj->getType() != Git::OBJ_TAG) { return; } $tag['id'] = sha1_hex($tag_id); if ($obj->object !== null) { $tag['object'] = sha1_hex($obj->object); } if ($obj->objtype !== null) { $tag['type'] = Git::getTypeName($obj->objtype); } if ($obj->tag !== null) { $tag['name'] = $obj->tag; } if ($obj->tagger !== null) { $tag['author'] = $obj->tagger->name; $tag['epoch'] = $obj->tagger->time; $tag['tz'] = sprintf("%+03d%02d", $obj->tagger->offset / 3600, abs($obj->tagger->offset % 3600 / 60)); } $tag['comment'] = explode("\n", $obj->summary . "\n" . $obj->detail); if (!isset($tag['name'])) { return null; } return $tag; }
/** * @brief Write this object in its serialized form to the git repository * given at creation time. */ public function write() { $sha1 = sha1_hex($this->name); $path = sprintf('%s/objects/%s/%s', $this->repo->dir, substr($sha1, 0, 2), substr($sha1, 2)); if (file_exists($path)) { return FALSE; } $dir = dirname($path); if (!is_dir($dir)) { mkdir(dirname($path), 0770); } $f = fopen($path, 'ab'); flock($f, LOCK_EX); ftruncate($f, 0); $data = $this->serialize(); $data = Git::getTypeName($this->type) . ' ' . strlen($data) . "" . $data; fwrite($f, gzcompress($data)); fclose($f); return TRUE; }
protected function addObject($obj, $data) { $hash = hash_init("sha1"); hash_update($hash, Git::getTypeName($obj->type)); hash_update($hash, ' '); hash_update($hash, strlen($data)); hash_update($hash, ""); hash_update($hash, $data); $hash = hash_final($hash, true); if (isset($this->objects[$hash])) { throw new Exception(sprintf("duplicate object %s\n", sha1_hex($hash))); } $this->objects[$hash] = $obj; return $hash; }
public function _serialize() { $s = ''; if ($this->object !== null) { $s .= sprintf("object %s\n", sha1_hex($this->object)); $s .= sprintf("type %s\n", Git::getTypeName($this->objtype)); } if ($this->tag !== null) { $s .= sprintf("tag %s\n", $this->tagger->serialize()); } if ($this->tagger !== null) { $s .= sprintf("tagger %s\n", $this->tagger->serialize()); } $s .= "\n" . $this->summary . "\n" . $this->detail; return $s; }