コード例 #1
0
 /**
  * Get a commit
  *
  * @param string $hash commit hash
  * @return GitPHP_Commit|null commit objet
  */
 public function GetCommit($hash)
 {
     if (empty($hash)) {
         return null;
     }
     if (preg_match('/^[0-9A-Fa-f]{4,39}$/', $hash)) {
         $fullHash = $this->project->ExpandHash($hash);
         if ($fullHash == $hash) {
             throw new GitPHP_InvalidHashException($hash);
         }
         $hash = $fullHash;
     }
     if (!preg_match('/^[0-9A-Fa-f]{40}$/', $hash)) {
         return null;
     }
     $key = GitPHP_Commit::CacheKey($this->project->GetProject(), $hash);
     $commit = null;
     if ($this->memoryCache) {
         $commit = $this->memoryCache->Get($key);
     }
     if (!$commit) {
         if ($this->cache) {
             $commit = $this->cache->Get($key);
         }
         $strategy = null;
         if ($this->compat) {
             $strategy = new GitPHP_CommitLoad_Git($this->exe);
         } else {
             $strategy = new GitPHP_CommitLoad_Raw($this->objectLoader, $this->exe);
         }
         if ($commit) {
             $commit->SetProject($this->project);
             $commit->SetStrategy($strategy);
         } else {
             $commit = new GitPHP_Commit($this->project, $hash, $strategy);
         }
         $commit->AddObserver($this);
         if ($this->memoryCache) {
             $this->memoryCache->Set($key, $commit);
         }
     }
     return $commit;
 }
コード例 #2
0
ファイル: CommitTest.php プロジェクト: hmcclungiii/gitphp
 public function testObserverNotification()
 {
     $commit = new GitPHP_Commit($this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock(), '1234567890abcdef1234567890ABCDEF12345678', $this->getMockCommitLoader());
     $observer = $this->getMock('GitPHP_Observer_Interface');
     $matcher = $this->once();
     $observer->expects($matcher)->method('ObjectChanged')->with($this->isInstanceOf('GitPHP_Commit'), $this->equalTo(GitPHP_Observer_Interface::CacheableDataChange));
     $commit->AddObserver($observer);
     $title = $commit->GetTitle();
     $title = $commit->GetTitle();
     //cached
     $this->assertEquals(1, $matcher->getInvocationCount());
 }