コード例 #1
0
ファイル: CommitTest.php プロジェクト: hmcclungiii/gitphp
 public function testGetHash()
 {
     $loadstrategy = $this->getMockCommitLoader();
     $loadstrategy->expects($this->any())->method('LoadsAbbreviatedHash')->will($this->returnValue(true));
     $commit = new GitPHP_Commit($this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock(), '1234567890abcdef1234567890ABCDEF12345678', $loadstrategy);
     $this->assertEquals('abbrevhash', $commit->GetHash(true));
     $this->assertEquals('abbrevhash', $commit->GetHash(true));
     //cached
     $this->assertEquals('1234567890abcdef1234567890ABCDEF12345678', $commit->GetHash());
 }
コード例 #2
0
ファイル: TagList.class.php プロジェクト: fboender/gitphp
 /**
  * Get tags pointing to a commit
  *
  * @param GitPHP_Commit $commit commit
  * @return GitPHP_Tag[] array of tags
  */
 public function GetCommitTags($commit)
 {
     if (!$commit) {
         return array();
     }
     $commitHash = $commit->GetHash();
     if (!$this->dataLoaded) {
         $this->LoadData();
     }
     if (!isset($this->invertedRefs[$commitHash])) {
         return array();
     }
     $tagNames = $this->invertedRefs[$commitHash];
     $tags = array();
     foreach ($tagNames as $tag) {
         if (isset($this->commits[$tag])) {
             if ($this->commits[$tag] == $commitHash) {
                 $tagObj = $this->project->GetObjectManager()->GetTag($tag, $this->refs[$tag]);
                 $tagObj->SetCommitHash($this->commits[$tag]);
                 $tags[] = $tagObj;
             }
         } else {
             $tagObj = $this->project->GetObjectManager()->GetTag($tag, $this->refs[$tag]);
             $tagCommitHash = $tagObj->GetCommitHash();
             if (!empty($tagCommitHash)) {
                 $this->commits[$tag] = $tagCommitHash;
             }
             if ($tagCommitHash == $commitHash) {
                 $tags[] = $tagObj;
             }
         }
     }
     return $tags;
 }
コード例 #3
0
 /**
  * Gets the containing tag for a commit
  *
  * @param GitPHP_Commit $commit commit
  * @return string containing tag
  */
 public function LoadContainingTag($commit)
 {
     if (!$commit) {
         return;
     }
     $args = array();
     $args[] = '--tags';
     $args[] = $commit->GetHash();
     $revs = explode("\n", $this->exe->Execute($commit->GetProject()->GetPath(), GIT_NAME_REV, $args));
     foreach ($revs as $revline) {
         if (preg_match('/^([0-9a-fA-F]{40})\\s+tags\\/(.+)(\\^[0-9]+|\\~[0-9]+)$/', $revline, $regs)) {
             if ($regs[1] == $commit->GetHash()) {
                 return $regs[2];
             }
         }
     }
 }
コード例 #4
0
ファイル: HeadList.class.php プロジェクト: fboender/gitphp
 /**
  * Gets heads that point to a commit
  *
  * @param GitPHP_Commit $commit commit
  * @return GitPHP_Head[] array of heads
  */
 public function GetCommitHeads($commit)
 {
     if (!$commit) {
         return array();
     }
     $commitHash = $commit->GetHash();
     if (!$this->dataLoaded) {
         $this->LoadData();
     }
     if (!isset($this->invertedRefs[$commitHash])) {
         return array();
     }
     $headNames = $this->invertedRefs[$commitHash];
     $heads = array();
     foreach ($headNames as $head) {
         $heads[] = $this->project->GetObjectManager()->GetHead($head, $commitHash);
     }
     return $heads;
 }
コード例 #5
0
ファイル: FileBlame.class.php プロジェクト: fboender/gitphp
 /**
  * Constructor
  *
  * @param GitPHP_Project $project project
  * @param GitPHP_Commit $commit commit to trace blame from
  * @param string $path file path to trace blame of
  * @param GitPHP_GitExe $exe git executable
  */
 public function __construct($project, $commit, $path, $exe)
 {
     if (!$project) {
         throw new Exception('Project is required');
     }
     if (!$commit) {
         throw new Exception('Commit is required');
     }
     if (empty($path)) {
         throw new Exception('Path is required');
     }
     if (!$exe) {
         throw new Exception('Git exe is required');
     }
     $this->project = $project;
     $this->commitHash = $commit->GetHash();
     $this->path = $path;
     $this->exe = $exe;
 }
コード例 #6
0
ファイル: RevList.class.php プロジェクト: fboender/gitphp
 /**
  * Sets the head this log will walk from
  *
  * @param GitPHP_Commit $head head commit
  */
 public function SetHead($head)
 {
     if ($head) {
         $this->SetHeadHash($head->GetHash());
     } else {
         $this->SetHeadHash(null);
     }
 }
コード例 #7
0
 /**
  * Sets the commit this object belongs to
  *
  * @param GitPHP_Commit $commit commit object
  */
 public function SetCommit($commit)
 {
     if (!$commit) {
         return;
     }
     $this->SetCommitHash($commit->GetHash());
 }
コード例 #8
0
 /**
  * Gets the data for a commit
  *
  * @param GitPHP_Commit $commit commit
  * @return array commit data
  */
 public function Load($commit)
 {
     if (!$commit) {
         return;
     }
     $abbreviatedHash = null;
     $tree = null;
     $parents = array();
     $author = null;
     $authorEpoch = null;
     $authorTimezone = null;
     $committer = null;
     $committerEpoch = null;
     $committerTimezone = null;
     $title = null;
     $comment = array();
     $commitHash = $commit->GetHash();
     $projectPath = $commit->GetProject()->GetPath();
     /* Try to get abbreviated hash first try. Go up to max hash length on collision. */
     for ($i = 7; $i <= 40; $i++) {
         $abbreviatedHash = substr($commitHash, 0, $i);
         $ret = $this->exe->GetObjectData($projectPath, $abbreviatedHash);
         if (!$ret) {
             return false;
         }
         if ($ret['hash'] !== $commitHash) {
             continue;
         }
         $lines = explode("\n", $ret['contents']);
         break;
     }
     $linecount = count($lines);
     $i = 0;
     $encoding = null;
     /* Commit header */
     for ($i = 0; $i < $linecount; $i++) {
         $line = $lines[$i];
         if (preg_match('/^tree ([0-9a-fA-F]{40})$/', $line, $regs)) {
             /* Tree */
             $tree = $regs[1];
         } else {
             if (preg_match('/^parent ([0-9a-fA-F]{40})$/', $line, $regs)) {
                 /* Parent */
                 $parents[] = $regs[1];
             } else {
                 if (preg_match('/^author (.*) ([0-9]+) (.*)$/', $line, $regs)) {
                     /* author data */
                     $author = $regs[1];
                     $authorEpoch = $regs[2];
                     $authorTimezone = $regs[3];
                 } else {
                     if (preg_match('/^committer (.*) ([0-9]+) (.*)$/', $line, $regs)) {
                         /* committer data */
                         $committer = $regs[1];
                         $committerEpoch = $regs[2];
                         $committerTimezone = $regs[3];
                     } else {
                         if (preg_match('/^encoding (.+)$/', $line, $regs)) {
                             $gitEncoding = trim($regs[1]);
                             if (strlen($gitEncoding) > 0 && function_exists('mb_list_encodings')) {
                                 $supportedEncodings = mb_list_encodings();
                                 $encIdx = array_search(strtolower($gitEncoding), array_map('strtolower', $supportedEncodings));
                                 if ($encIdx !== false) {
                                     $encoding = $supportedEncodings[$encIdx];
                                 }
                             }
                             $encoding = trim($regs[1]);
                         } else {
                             if (strlen($line) == 0) {
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     /* Commit body */
     for ($i += 1; $i < $linecount; $i++) {
         $trimmed = trim($lines[$i]);
         if (strlen($trimmed) > 0 && strlen($encoding) > 0 && function_exists('mb_convert_encoding')) {
             $trimmed = mb_convert_encoding($trimmed, 'UTF-8', $encoding);
         }
         if (empty($title) && strlen($trimmed) > 0) {
             $title = $trimmed;
         }
         if (!empty($title)) {
             if (strlen($trimmed) > 0 || $i < $linecount - 1) {
                 $comment[] = $trimmed;
             }
         }
     }
     return array($abbreviatedHash, $tree, $parents, $author, $authorEpoch, $authorTimezone, $committer, $committerEpoch, $committerTimezone, $title, $comment);
 }
コード例 #9
0
 /**
  * Gets the data for a commit
  *
  * @param GitPHP_Commit $commit commit
  * @return array commit data
  */
 public function Load($commit)
 {
     if (!$commit) {
         return;
     }
     $abbreviatedHash = null;
     $tree = null;
     $parents = array();
     $author = null;
     $authorEpoch = null;
     $authorTimezone = null;
     $committer = null;
     $committerEpoch = null;
     $committerTimezone = null;
     $title = null;
     $comment = array();
     $data = $this->objectLoader->GetObject($commit->GetHash());
     if (empty($data)) {
         return;
     }
     $lines = explode("\n", $data);
     $linecount = count($lines);
     $i = 0;
     $encoding = null;
     /* Commit header */
     for ($i = 0; $i < $linecount; $i++) {
         $line = $lines[$i];
         if (preg_match('/^tree ([0-9a-fA-F]{40})$/', $line, $regs)) {
             /* Tree */
             $tree = $regs[1];
         } else {
             if (preg_match('/^parent ([0-9a-fA-F]{40})$/', $line, $regs)) {
                 /* Parent */
                 $parents[] = $regs[1];
             } else {
                 if (preg_match('/^author (.*) ([0-9]+) (.*)$/', $line, $regs)) {
                     /* author data */
                     $author = $regs[1];
                     $authorEpoch = $regs[2];
                     $authorTimezone = $regs[3];
                 } else {
                     if (preg_match('/^committer (.*) ([0-9]+) (.*)$/', $line, $regs)) {
                         /* committer data */
                         $committer = $regs[1];
                         $committerEpoch = $regs[2];
                         $committerTimezone = $regs[3];
                     } else {
                         if (preg_match('/^encoding (.+)$/', $line, $regs)) {
                             $gitEncoding = trim($regs[1]);
                             if (strlen($gitEncoding) > 0 && function_exists('mb_list_encodings')) {
                                 $supportedEncodings = mb_list_encodings();
                                 $encIdx = array_search(strtolower($gitEncoding), array_map('strtolower', $supportedEncodings));
                                 if ($encIdx !== false) {
                                     $encoding = $supportedEncodings[$encIdx];
                                 }
                             }
                             $encoding = trim($regs[1]);
                         } else {
                             if (strlen($line) == 0) {
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     /* Commit body */
     for ($i += 1; $i < $linecount; $i++) {
         $trimmed = trim($lines[$i]);
         if (strlen($trimmed) > 0 && strlen($encoding) > 0 && function_exists('mb_convert_encoding')) {
             $trimmed = mb_convert_encoding($trimmed, 'UTF-8', $encoding);
         }
         if (empty($title) && strlen($trimmed) > 0) {
             $title = $trimmed;
         }
         if (!empty($title)) {
             if (strlen($trimmed) > 0 || $i < $linecount - 1) {
                 $comment[] = $trimmed;
             }
         }
     }
     return array($abbreviatedHash, $tree, $parents, $author, $authorEpoch, $authorTimezone, $committer, $committerEpoch, $committerTimezone, $title, $comment);
 }
コード例 #10
0
ファイル: Archive.class.php プロジェクト: fboender/gitphp
 /**
  * Sets the object for this archive
  *
  * @param GitPHP_Commit|GitPHP_Tree|null $object the git object
  */
 public function SetObject($object)
 {
     // Archive only works for commits and trees
     if ($object == null) {
         $this->objectHash = '';
         $this->objectType = '';
         return;
     }
     if ($object instanceof GitPHP_Commit) {
         $this->objectType = 'commit';
         $this->objectHash = $object->GetHash();
         return;
     }
     if ($object instanceof GitPHP_Tree) {
         $this->objectType = 'tree';
         $this->objectHash = $object->GetHash();
         return;
     }
     throw new Exception('Invalid source object for archive');
 }