/** * 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) { $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); // Read commit metadata $format = new PrettyFormat(); $data = $format->parse($commitInfo); $commit = new Commit(); $commit->importData($data[0]); if ($commit->getParentsHash()) { $command = 'diff ' . $commitHash . '~1..' . $commitHash; $logs = explode("\n", $this->getClient()->run($this, $command)); } $commit->setDiffs($this->readDiffLogs($logs)); return $commit; }
/** * 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; }