Issue #57: Interleave commits in blame

This commit is contained in:
Dave Hall
2012-06-26 21:47:19 +10:00
parent ad67163c09
commit 158150d6c3
2 changed files with 12 additions and 9 deletions

View File

@@ -477,24 +477,27 @@ class Repository
*/ */
public function getBlame($file) public function getBlame($file)
{ {
$blame = array();
$logs = $this->getClient()->run($this, "blame -s $file"); $logs = $this->getClient()->run($this, "blame -s $file");
$logs = explode("\n", $logs); $logs = explode("\n", $logs);
$i = 0;
$previous_commit = '';
foreach ($logs as $log) { foreach ($logs as $log) {
if ($log == '') { if ($log == '') {
continue; continue;
} }
$split = preg_split("/[a-zA-Z0-9^]{8}[\s]+[0-9]+\)/", $log); preg_match_all("/([a-zA-Z0-9^]{8})[\s]+(.+)[\s]+([0-9]+)\)(.+)/", $log, $match);
preg_match_all("/([a-zA-Z0-9^]{8})[\s]+([0-9]+)\)/", $log, $match);
$commit = $match[1][0]; $current_commit = $match[1][0];
if ($current_commit != $previous_commit) {
if (!isset($blame[$commit]['line'])) { ++$i;
$blame[$commit]['line'] = ''; $blame[$i] = array('line' => '', 'commit' => $current_commit);
} }
$blame[$commit]['line'] .= PHP_EOL . $split[1]; $blame[$i]['line'] .= PHP_EOL . $match[4][0];
$previous_commit = $current_commit;
} }
return $blame; return $blame;

View File

@@ -21,9 +21,9 @@
<div class="meta">{{ file }}</div> <div class="meta">{{ file }}</div>
</div> </div>
<table class="blame-view"> <table class="blame-view">
{% for commit, blame in blames %} {% for blame in blames %}
<tr> <tr>
<td class="commit"><a href="{{ baseurl }}/{{ repo }}/commit/{{ commit }}/">{{ commit }}</a></td> <td class="commit"><a href="{{ baseurl }}/{{ repo }}/commit/{{ blame.commit }}/">{{ blame.commit }}</a></td>
<td><pre>{{ blame.line }}</pre></td> <td><pre>{{ blame.line }}</pre></td>
</tr> </tr>
{% endfor %} {% endfor %}