Exemplo n.º 1
0
 /**
  * Gets a single tag
  *
  * @param string $tag tag to find
  * @param string $hash hash of tag, if known
  * @return GitPHP_Tag tag object
  */
 public function GetTag($tag, $hash = '')
 {
     if (empty($tag)) {
         return null;
     }
     $key = GitPHP_Tag::CacheKey($this->project->GetProject(), $tag);
     $tagObj = null;
     if ($this->memoryCache) {
         $tagObj = $this->memoryCache->Get($key);
     }
     if (!$tagObj) {
         if ($this->cache) {
             $tagObj = $this->cache->Get($key);
         }
         $strategy = null;
         if ($this->compat) {
             $strategy = new GitPHP_TagLoad_Git($this->exe);
         } else {
             $strategy = new GitPHP_TagLoad_Raw($this->objectLoader);
         }
         if ($tagObj) {
             $tagObj->SetProject($this->project);
             $tagObj->SetStrategy($strategy);
         } else {
             $tagObj = new GitPHP_Tag($this->project, $tag, $strategy, $hash);
         }
         $tagObj->AddObserver($this);
         if ($this->memoryCache) {
             $this->memoryCache->Set($key, $tagObj);
         }
     }
     return $tagObj;
 }
Exemplo n.º 2
0
 public function testObserver()
 {
     $projectmock = $this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock();
     $tag = new GitPHP_Tag($projectmock, 'sometag', $this->getMock('GitPHP_TagLoadStrategy_Interface'));
     $observermock = $this->getMock('GitPHP_Observer_Interface');
     $matcher = $this->once();
     $observermock->expects($matcher)->method('ObjectChanged')->with($this->isInstanceOf('GitPHP_Tag'), $this->equalTo(GitPHP_Observer_Interface::CacheableDataChange));
     $tag->AddObserver($observermock);
     $tagger = $tag->GetTagger();
     $tagger = $tag->GetTagger();
     //cached
     $this->assertEquals(1, $matcher->getInvocationCount());
 }
Exemplo n.º 3
0
 /**
  * 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();
     $data = $this->objectLoader->GetObject($tag->GetHash(), $packedType);
     if ($packedType == GitPHP_Pack::OBJ_COMMIT) {
         /* light tag */
         $object = $tag->GetHash();
         $commitHash = $tag->GetHash();
         $type = 'commit';
         return array($type, $object, $commitHash, $tagger, $taggerEpoch, $taggerTimezone, $comment);
     }
     $lines = explode("\n", $data);
     if (!isset($lines[0])) {
         return;
     }
     $objectHash = null;
     $readInitialData = false;
     foreach ($lines as $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':
             $object = $tag->GetProject()->GetTagList()->GetTagNameFromHash($objectHash);
             break;
         case 'blob':
             $object = $objectHash;
             break;
     }
     return array($type, $object, $commitHash, $tagger, $taggerEpoch, $taggerTimezone, $comment);
 }
Exemplo n.º 4
0
 /**
  * Compares to tags by creation epoch
  *
  * @param GitPHP_Tag $a first tag
  * @param GitPHP_Tag $b second tag
  * @return integer comparison result
  */
 public static function CompareCreationEpoch($a, $b)
 {
     $aEpoch = $a->GetCreationEpoch();
     $bEpoch = $b->GetCreationEpoch();
     if ($aEpoch == $bEpoch) {
         return 0;
     }
     return $aEpoch < $bEpoch ? 1 : -1;
 }
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
0
 /**
  * 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);
 }