diff --git a/src/GitList/Controller/CommitController.php b/src/GitList/Controller/CommitController.php index 728b861..2597556 100644 --- a/src/GitList/Controller/CommitController.php +++ b/src/GitList/Controller/CommitController.php @@ -72,7 +72,7 @@ class CommitController implements ControllerProviderInterface ->assert('branch', '[\w-._\/]+') ->bind('searchcommits'); - $route->get('{repo}/commit/{commit}/', function($repo, $commit) use ($app) { + $route->get('{repo}/commit/{commit}', function($repo, $commit) use ($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); $commit = $repository->getCommit($commit); diff --git a/src/GitList/Git/Repository.php b/src/GitList/Git/Repository.php index 50d1f37..edd399b 100644 --- a/src/GitList/Git/Repository.php +++ b/src/GitList/Git/Repository.php @@ -37,6 +37,44 @@ class Repository extends BaseRepository return $commit; } + /** + * Blames the provided file and parses the output + * + * @param string $file File that will be blamed + * @return array Commits hashes containing the lines + */ + public function getBlame($file) + { + $blame = array(); + $logs = $this->getClient()->run($this, "blame --root -sl $file"); + $logs = explode("\n", $logs); + + $i = 0; + $previousCommit = ''; + foreach ($logs as $log) { + if ($log == '') { + continue; + } + + preg_match_all("/([a-zA-Z0-9]{40})\s+.*?([0-9]+)\)(.+)/", $log, $match); + + $currentCommit = $match[1][0]; + if ($currentCommit != $previousCommit) { + ++$i; + $blame[$i] = array( + 'line' => '', + 'commit' => $currentCommit, + 'commitShort' => substr($currentCommit, 0, 8) + ); + } + + $blame[$i]['line'] .= PHP_EOL . $match[3][0]; + $previousCommit = $currentCommit; + } + + return $blame; + } + /** * Show the repository commit log with pagination * diff --git a/views/blame.twig b/views/blame.twig index 039de5c..d58d918 100644 --- a/views/blame.twig +++ b/views/blame.twig @@ -14,7 +14,7 @@
| {{ blame.commit }} | +{{ blame.commitShort }} | {{ blame.line }} |
- View {{ item.shortHash }}
+ View {{ item.shortHash }}
{{ item.message }}{{ item.author.name }} authored in {{ item.date | date('d/m/Y \\a\\t H:i:s') }} |
diff --git a/views/rss.twig b/views/rss.twig
index aca671f..e14e783 100644
--- a/views/rss.twig
+++ b/views/rss.twig
@@ -9,7 +9,7 @@