Properly parsing commit body, fixes #137

This commit is contained in:
Klaus Silveira
2013-03-29 00:44:06 -03:00
parent b73af1a64e
commit 919c953f83
2 changed files with 10 additions and 3 deletions

View File

@@ -42,12 +42,16 @@ class Repository extends BaseRepository
*/ */
public function getCommit($commitHash) 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></item>\" $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");
$logs = explode("\n", $logs); $xmlEnd = strpos($logs, '</item>') + 7;
$commitInfo = substr($logs, 0, $xmlEnd);
$commitData = substr($logs, $xmlEnd);
$logs = explode("\n", $commitData);
array_shift($logs);
// Read commit metadata // Read commit metadata
$format = new PrettyFormat; $format = new PrettyFormat;
$data = $format->parse($logs[0]); $data = $format->parse($commitInfo);
$commit = new Commit; $commit = new Commit;
$commit->importData($data[0]); $commit->importData($data[0]);

View File

@@ -13,6 +13,9 @@
<h4>{{ commit.message }}</h4> <h4>{{ commit.message }}</h4>
</div> </div>
<div class="commit-body"> <div class="commit-body">
{% if commit.body is not empty %}
<p>{{ commit.body | nl2br }}</p>
{% endif %}
<img src="https://gravatar.com/avatar/{{ commit.author.email | lower | md5 }}?s=32" class="pull-left space-right" /> <img src="https://gravatar.com/avatar/{{ commit.author.email | lower | md5 }}?s=32" class="pull-left space-right" />
<span><a href="mailto:{{ commit.author.email }}">{{ commit.author.name }}</a> authored on {{ commit.date | date('d/m/Y \\a\\t H:i:s') }}<br />Showing {{ commit.changedFiles }} changed files</span> <span><a href="mailto:{{ commit.author.email }}">{{ commit.author.name }}</a> authored on {{ commit.date | date('d/m/Y \\a\\t H:i:s') }}<br />Showing {{ commit.changedFiles }} changed files</span>
</div> </div>