From 158150d6c39e6ade30d0799ea797509dc7cf677d Mon Sep 17 00:00:00 2001 From: Dave Hall Date: Tue, 26 Jun 2012 21:47:19 +1000 Subject: [PATCH] Issue #57: Interleave commits in blame --- lib/Git/Repository.php | 17 ++++++++++------- views/blame.twig | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/Git/Repository.php b/lib/Git/Repository.php index 2b930f4..eb8cebe 100644 --- a/lib/Git/Repository.php +++ b/lib/Git/Repository.php @@ -477,24 +477,27 @@ class Repository */ public function getBlame($file) { + $blame = array(); $logs = $this->getClient()->run($this, "blame -s $file"); $logs = explode("\n", $logs); + $i = 0; + $previous_commit = ''; foreach ($logs as $log) { if ($log == '') { continue; } - $split = preg_split("/[a-zA-Z0-9^]{8}[\s]+[0-9]+\)/", $log); - preg_match_all("/([a-zA-Z0-9^]{8})[\s]+([0-9]+)\)/", $log, $match); + preg_match_all("/([a-zA-Z0-9^]{8})[\s]+(.+)[\s]+([0-9]+)\)(.+)/", $log, $match); - $commit = $match[1][0]; - - if (!isset($blame[$commit]['line'])) { - $blame[$commit]['line'] = ''; + $current_commit = $match[1][0]; + if ($current_commit != $previous_commit) { + ++$i; + $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; diff --git a/views/blame.twig b/views/blame.twig index 022790d..390053e 100644 --- a/views/blame.twig +++ b/views/blame.twig @@ -21,9 +21,9 @@
{{ file }}
- {% for commit, blame in blames %} + {% for blame in blames %} - + {% endfor %}
{{ commit }}{{ blame.commit }}
{{ blame.line }}