mirror of
https://github.com/klaussilveira/gitlist.git
synced 2025-11-17 19:20:56 +01:00
improve get blame method retrieving long revisions to avoid ambiguity and omitting the caret of revisions (boundary commits)
This commit is contained in:
@@ -72,7 +72,7 @@ class CommitController implements ControllerProviderInterface
|
|||||||
->assert('branch', '[\w-._\/]+')
|
->assert('branch', '[\w-._\/]+')
|
||||||
->bind('searchcommits');
|
->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);
|
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||||
$commit = $repository->getCommit($commit);
|
$commit = $repository->getCommit($commit);
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,44 @@ class Repository extends BaseRepository
|
|||||||
return $commit;
|
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
|
* Show the repository commit log with pagination
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<table class="blame-view">
|
<table class="blame-view">
|
||||||
{% for blame in blames %}
|
{% for blame in blames %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="commit"><a href="{{ path('commit', {repo: repo, commit: blame.commit}) }}">{{ blame.commit }}</a></td>
|
<td class="commit"><a href="{{ path('commit', {repo: repo, commit: blame.commit}) }}">{{ blame.commitShort }}</a></td>
|
||||||
<td><pre>{{ blame.line }}</pre></td>
|
<td><pre>{{ blame.line }}</pre></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td width="5%"><img src="http://gravatar.com/avatar/{{ item.author.email | md5 }}?s=40" /></td>
|
<td width="5%"><img src="http://gravatar.com/avatar/{{ item.author.email | md5 }}?s=40" /></td>
|
||||||
<td width="95%">
|
<td width="95%">
|
||||||
<span class="pull-right"><a class="btn btn-small" href="{{ path('commit', {repo: repo, commit: item.shortHash}) }}"><i class="icon-list-alt"></i> View {{ item.shortHash }}</a></span>
|
<span class="pull-right"><a class="btn btn-small" href="{{ path('commit', {repo: repo, commit: item.hash}) }}"><i class="icon-list-alt"></i> View {{ item.shortHash }}</a></span>
|
||||||
<h4>{{ item.message }}</h4>
|
<h4>{{ item.message }}</h4>
|
||||||
<span><a href="mailto:{{ item.author.email }}">{{ item.author.name }}</a> authored in {{ item.date | date('d/m/Y \\a\\t H:i:s') }}</span>
|
<span><a href="mailto:{{ item.author.email }}">{{ item.author.name }}</a> authored in {{ item.date | date('d/m/Y \\a\\t H:i:s') }}</span>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<title>{{ commit.message }}</title>
|
<title>{{ commit.message }}</title>
|
||||||
<description>{{ commit.author.name }} authored {{ commit.shortHash }} in {{ commit.date | date('d/m/Y \\a\\t H:i:s') }}</description>
|
<description>{{ commit.author.name }} authored {{ commit.shortHash }} in {{ commit.date | date('d/m/Y \\a\\t H:i:s') }}</description>
|
||||||
<link>{{ path('commit', {repo: repo, commit: commit.shortHash}) }}</link>
|
<link>{{ path('commit', {repo: repo, commit: commit.hash}) }}</link>
|
||||||
<pubDate>{{ commit.date | date('r') }}</pubDate>
|
<pubDate>{{ commit.date | date('r') }}</pubDate>
|
||||||
</item>
|
</item>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
Reference in New Issue
Block a user