Example #1
0
 /**
  * @param Commit $commit
  */
 public function addCommit(Commit $commit)
 {
     $email = $commit->getAuthor()->getEmail();
     $commitDate = $commit->getCommiterDate()->format('Y-m-d');
     if (!isset($this->items[$email])) {
         $this->items[$email] = new Collection();
     }
     $this->items[$email]->items[$commitDate][] = $commit;
     ksort($this->items[$email]->items);
 }
Example #2
0
 public function searchCommitLog($query)
 {
     $command = "log --grep='{$query}' --pretty=format:'<item><hash>%H</hash><short_hash>%h</short_hash><tree>%T</tree><parent>%P</parent><author>%an</author><author_email>%ae</author_email><date>%at</date><commiter>%cn</commiter><commiter_email>%ce</commiter_email><commiter_date>%ct</commiter_date><message><![CDATA[%s]]></message></item>'";
     $logs = $this->getPrettyFormat($command);
     foreach ($logs as $log) {
         $commit = new Commit();
         $commit->importData($log);
         $commits[] = $commit;
     }
     return $commits;
 }
Example #3
0
 /**
  * Show the data from a specific commit
  *
  * @param  string $commitHash Hash of the specific commit to read data
  * @return array  Commit data
  */
 public function getCommit($commitHash)
 {
     if (version_compare($this->getClient()->getVersion(), '1.8.4', '>=')) {
         $logs = $this->getClient()->run($this, "show --ignore-blank-lines -w -b --pretty=format:\"<item><hash>%H</hash><short_hash>%h</short_hash><tree>%T</tree><parents>%P</parents><author>%an</author><author_email>%ae</author_email><date>%at</date><commiter>%cn</commiter><commiter_email>%ce</commiter_email><commiter_date>%ct</commiter_date><message><![CDATA[%s]]></message><body><![CDATA[%b]]></body></item>\" {$commitHash}");
     } else {
         $logs = $this->getClient()->run($this, "show --pretty=format:\"<item><hash>%H</hash><short_hash>%h</short_hash><tree>%T</tree><parents>%P</parents><author>%an</author><author_email>%ae</author_email><date>%at</date><commiter>%cn</commiter><commiter_email>%ce</commiter_email><commiter_date>%ct</commiter_date><message><![CDATA[%s]]></message><body><![CDATA[%b]]></body></item>\" {$commitHash}");
     }
     $xmlEnd = strpos($logs, '</item>') + 7;
     $commitInfo = substr($logs, 0, $xmlEnd);
     $commitData = substr($logs, $xmlEnd);
     $logs = explode("\n", $commitData);
     array_shift($logs);
     // Read commit metadata
     $format = new PrettyFormat();
     $data = $format->parse($commitInfo);
     $commit = new Commit();
     $commit->importData($data[0]);
     if (empty($logs[1])) {
         $logs = explode("\n", $this->getClient()->run($this, 'diff ' . $commitHash . '~1..' . $commitHash));
     }
     $commit->setDiffs($this->readDiffLogs($logs));
     return $commit;
 }
Example #4
0
 public function testImportData()
 {
     $data = array('hash' => '209908f247194b1adc836f2e50f957cb1f11f41c', 'short_hash' => '209908f', 'tree' => '0a1f6638ccfc6d6b34be8a913144304355d23cc3', 'parents' => '6e6951114ccf7b162e2a57b0462b39ca972f476f 1e8fd833f71fd20f8b176c79c705b9f096434126', 'author' => 'The Author', 'author_email' => '*****@*****.**', 'date' => '1347372763', 'commiter' => 'The Commiter', 'commiter_email' => '*****@*****.**', 'commiter_date' => '1347372763', 'message' => 'Test commit', 'body' => 'Test body');
     $commit = new Commit();
     $commit->importData($data);
     $this->assertEquals('209908f247194b1adc836f2e50f957cb1f11f41c', $commit->getHash());
     $this->assertEquals('209908f', $commit->getShortHash());
     $this->assertEquals('0a1f6638ccfc6d6b34be8a913144304355d23cc3', $commit->getTreeHash());
     $this->assertEquals(array('6e6951114ccf7b162e2a57b0462b39ca972f476f', '1e8fd833f71fd20f8b176c79c705b9f096434126'), $commit->getParentsHash());
     $this->assertEquals('The Author', $commit->getAuthor()->getName());
     $this->assertEquals('*****@*****.**', $commit->getAuthor()->getEmail());
     $this->assertEquals(new DateTime('@1347372763'), $commit->getDate());
     $this->assertEquals('The Commiter', $commit->getCommiter()->getName());
     $this->assertEquals('*****@*****.**', $commit->getCommiter()->getEmail());
     $this->assertEquals(new DateTime('@1347372763'), $commit->getCommiterDate());
     $this->assertEquals('Test commit', $commit->getMessage());
     $this->assertEquals('Test body', $commit->getBody());
 }
Example #5
0
 public function searchCommitLog($query, $branch)
 {
     $query = escapeshellarg($query);
     $query = strtr($query, array('[' => '\\[', ']' => '\\]'));
     $command = "log --grep={$query} -i --pretty=format:\"<item><hash>%H</hash>" . "<short_hash>%h</short_hash><tree>%T</tree><parents>%P</parents>" . "<author>%aN</author><author_email>%aE</author_email>" . "<date>%at</date><commiter>%cN</commiter>" . "<commiter_email>%cE</commiter_email>" . "<commiter_date>%ct</commiter_date>" . "<message><![CDATA[%s]]></message></item>\"" . " {$branch}";
     try {
         $logs = $this->getPrettyFormat($command);
     } catch (\RuntimeException $e) {
         return array();
     }
     foreach ($logs as $log) {
         $commit = new Commit();
         $commit->importData($log);
         $commits[] = $commit;
     }
     return $commits;
 }
Example #6
0
 /**
  * @param Commit $commit
  */
 public function addCommit(Commit $commit)
 {
     $day = $commit->getCommiterDate()->format('Y-m-d');
     $this->items[$day][] = $commit;
 }
Example #7
0
 /**
  * @param Commit $commit
  */
 public function addCommit(Commit $commit)
 {
     $hour = $commit->getCommiterDate()->format('H');
     $this->items[$hour][] = $commit;
 }