/** * Gets an identifier for a tag * * @param string|GitPHP_Tag $value string or tag * @return string hash */ private static function GetTag($value) { if ($value instanceof GitPHP_Tag) { return $value->GetName(); } else { if (is_string($value)) { return $value; } } return null; }
/** * Compares two tags by age * * @param GitPHP_Tag $a first tag * @param GitPHP_Tag $b second tag * @return integer comparison result */ public static function CompareAge($a, $b) { $aObj = $a->GetObject(); $bObj = $b->GetObject(); if ($aObj instanceof GitPHP_Commit && $bObj instanceof GitPHP_Commit) { return GitPHP_Commit::CompareAge($aObj, $bObj); } if ($aObj instanceof GitPHP_Commit) { return 1; } if ($bObj instanceof GitPHP_Commit) { return -1; } return strcmp($a->GetName(), $b->GetName()); }
/** * Gets the data for a tag * * @param GitPHP_Tag $tag tag * @return array array of tag data */ public function Load($tag) { if (!$tag) { return; } $type = null; $object = null; $commitHash = null; $tagger = null; $taggerEpoch = null; $taggerTimezone = null; $comment = array(); $result = $this->exe->GetObjectData($tag->GetProject()->GetPath(), $tag->GetHash()); if ($result['type'] === 'commit') { /* light tag */ $object = $tag->GetHash(); $commitHash = $tag->GetHash(); $type = 'commit'; return array($type, $object, $commitHash, $tagger, $taggerEpoch, $taggerTimezone, $comment); } /* get data from tag object */ $result = $this->exe->GetObjectData($tag->GetProject()->GetPath(), $tag->GetName()); $lines = explode("\n", $result['contents']); if (!isset($lines[0])) { return; } $objectHash = null; $readInitialData = false; foreach ($lines as $i => $line) { if (!$readInitialData) { if (preg_match('/^object ([0-9a-fA-F]{40})$/', $line, $regs)) { $objectHash = $regs[1]; continue; } else { if (preg_match('/^type (.+)$/', $line, $regs)) { $type = $regs[1]; continue; } else { if (preg_match('/^tag (.+)$/', $line, $regs)) { continue; } else { if (preg_match('/^tagger (.*) ([0-9]+) (.*)$/', $line, $regs)) { $tagger = $regs[1]; $taggerEpoch = $regs[2]; $taggerTimezone = $regs[3]; continue; } } } } } $trimmed = trim($line); if (strlen($trimmed) > 0 || $readInitialData === true) { $comment[] = $line; } $readInitialData = true; } switch ($type) { case 'commit': $object = $objectHash; $commitHash = $objectHash; break; case 'tag': $args = array(); $args[] = 'tag'; $args[] = $objectHash; $ret = $this->exe->Execute($tag->GetProject()->GetPath(), GIT_CAT_FILE, $args); $lines = explode("\n", $ret); foreach ($lines as $i => $line) { if (preg_match('/^tag (.+)$/', $line, $regs)) { $name = trim($regs[1]); $object = $name; } } break; case 'blob': $object = $objectHash; break; } return array($type, $object, $commitHash, $tagger, $taggerEpoch, $taggerTimezone, $comment); }