mirror of
https://github.com/klaussilveira/gitlist.git
synced 2025-11-17 19:20:56 +01:00
Merge pull request #225 from marcoscoelho/path-to-avoid-errors
Path to avoid errors
This commit is contained in:
@@ -20,6 +20,7 @@ class CommitController implements ControllerProviderInterface
|
|||||||
$type = $file ? "$branch -- \"$file\"" : $branch;
|
$type = $file ? "$branch -- \"$file\"" : $branch;
|
||||||
$pager = $app['util.view']->getPager($app['request']->get('page'), $repository->getTotalCommits($type));
|
$pager = $app['util.view']->getPager($app['request']->get('page'), $repository->getTotalCommits($type));
|
||||||
$commits = $repository->getPaginatedCommits($type, $pager['current']);
|
$commits = $repository->getPaginatedCommits($type, $pager['current']);
|
||||||
|
$categorized = array();
|
||||||
|
|
||||||
foreach ($commits as $commit) {
|
foreach ($commits as $commit) {
|
||||||
$date = $commit->getDate();
|
$date = $commit->getDate();
|
||||||
@@ -48,7 +49,9 @@ class CommitController implements ControllerProviderInterface
|
|||||||
|
|
||||||
$route->post('{repo}/commits/search', function(Request $request, $repo) use ($app) {
|
$route->post('{repo}/commits/search', function(Request $request, $repo) use ($app) {
|
||||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||||
$commits = $repository->searchCommitLog($request->get('query'));
|
$query = $request->get('query');
|
||||||
|
$commits = $repository->searchCommitLog($query);
|
||||||
|
$categorized = array();
|
||||||
|
|
||||||
foreach ($commits as $commit) {
|
foreach ($commits as $commit) {
|
||||||
$date = $commit->getDate();
|
$date = $commit->getDate();
|
||||||
@@ -63,6 +66,7 @@ class CommitController implements ControllerProviderInterface
|
|||||||
'commits' => $categorized,
|
'commits' => $categorized,
|
||||||
'branches' => $repository->getBranches(),
|
'branches' => $repository->getBranches(),
|
||||||
'tags' => $repository->getTags(),
|
'tags' => $repository->getTags(),
|
||||||
|
'query' => $query
|
||||||
));
|
));
|
||||||
})->assert('repo', $app['util.routing']->getRepositoryRegex())
|
})->assert('repo', $app['util.routing']->getRepositoryRegex())
|
||||||
->bind('searchcommits');
|
->bind('searchcommits');
|
||||||
|
|||||||
@@ -53,8 +53,9 @@ class TreeController implements ControllerProviderInterface
|
|||||||
$branch = $repository->getHead();
|
$branch = $repository->getHead();
|
||||||
}
|
}
|
||||||
|
|
||||||
$breadcrumbs = $app['util.view']->getBreadcrumbs($tree);
|
$query = $request->get('query');
|
||||||
$results = $repository->searchTree($request->get('query'), $branch);
|
$breadcrumbs = array(array('dir' => 'Search results for: ' . $query, 'path' => ''));
|
||||||
|
$results = $repository->searchTree($query, $branch);
|
||||||
|
|
||||||
return $app['twig']->render('search.twig', array(
|
return $app['twig']->render('search.twig', array(
|
||||||
'results' => $results,
|
'results' => $results,
|
||||||
|
|||||||
@@ -4,10 +4,39 @@ namespace GitList\Git;
|
|||||||
|
|
||||||
use Gitter\Repository as BaseRepository;
|
use Gitter\Repository as BaseRepository;
|
||||||
use Gitter\Model\Commit\Commit;
|
use Gitter\Model\Commit\Commit;
|
||||||
|
use Gitter\PrettyFormat;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
|
||||||
class Repository extends BaseRepository
|
class Repository extends BaseRepository
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the data from a specific commit
|
||||||
|
*
|
||||||
|
* @param string $commitHash Hash of the specific commit to read data
|
||||||
|
* @return array Commit data
|
||||||
|
*/
|
||||||
|
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 = explode("\n", $logs);
|
||||||
|
|
||||||
|
// Read commit metadata
|
||||||
|
$format = new PrettyFormat;
|
||||||
|
$data = $format->parse($logs[0]);
|
||||||
|
$commit = new Commit;
|
||||||
|
$commit->importData($data[0]);
|
||||||
|
unset($logs[0]);
|
||||||
|
|
||||||
|
if (empty($logs[1])) {
|
||||||
|
$logs = explode("\n", $this->getClient()->run($this, 'diff ' . $commitHash . '~1..' . $commitHash));
|
||||||
|
}
|
||||||
|
|
||||||
|
$commit->setDiffs($this->readDiffLogs($logs));
|
||||||
|
|
||||||
|
return $commit;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the repository commit log with pagination
|
* Show the repository commit log with pagination
|
||||||
*
|
*
|
||||||
@@ -18,13 +47,17 @@ class Repository extends BaseRepository
|
|||||||
{
|
{
|
||||||
$page = 15 * $page;
|
$page = 15 * $page;
|
||||||
$pager = "--skip=$page --max-count=15";
|
$pager = "--skip=$page --max-count=15";
|
||||||
$command = "log $pager --pretty=format:'<item><hash>%H</hash><short_hash>%h</short_hash><tree>%T</tree><parent>%P</parent><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>'";
|
$command = "log $pager --pretty=format:\"<item><hash>%H</hash><short_hash>%h</short_hash><tree>%T</tree><parent>%P</parent><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>\"";
|
||||||
|
|
||||||
if ($file) {
|
if ($file) {
|
||||||
$command .= " $file";
|
$command .= " $file";
|
||||||
}
|
}
|
||||||
|
|
||||||
$logs = $this->getPrettyFormat($command);
|
try {
|
||||||
|
$logs = $this->getPrettyFormat($command);
|
||||||
|
} catch (\RuntimeException $e) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($logs as $log) {
|
foreach ($logs as $log) {
|
||||||
$commit = new Commit;
|
$commit = new Commit;
|
||||||
@@ -37,9 +70,14 @@ class Repository extends BaseRepository
|
|||||||
|
|
||||||
public function searchCommitLog($query)
|
public function searchCommitLog($query)
|
||||||
{
|
{
|
||||||
$command = "log --grep='$query' --pretty=format:'<item><hash>%H</hash><short_hash>%h</short_hash><tree>%T</tree><parent>%P</parent><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>'";
|
$query = escapeshellarg($query);
|
||||||
|
$command = "log --grep={$query} --pretty=format:\"<item><hash>%H</hash><short_hash>%h</short_hash><tree>%T</tree><parent>%P</parent><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>\"";
|
||||||
|
|
||||||
$logs = $this->getPrettyFormat($command);
|
try {
|
||||||
|
$logs = $this->getPrettyFormat($command);
|
||||||
|
} catch (\RuntimeException $e) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($logs as $log) {
|
foreach ($logs as $log) {
|
||||||
$commit = new Commit;
|
$commit = new Commit;
|
||||||
@@ -52,8 +90,10 @@ class Repository extends BaseRepository
|
|||||||
|
|
||||||
public function searchTree($query, $branch)
|
public function searchTree($query, $branch)
|
||||||
{
|
{
|
||||||
|
$query = escapeshellarg($query);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$results = $this->getClient()->run($this, "grep -I --line-number '$query' $branch");
|
$results = $this->getClient()->run($this, "grep -I --line-number {$query} $branch");
|
||||||
} catch (\RuntimeException $e) {
|
} catch (\RuntimeException $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -65,11 +105,13 @@ class Repository extends BaseRepository
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
preg_match_all('/([\w-._]+):(.+):([0-9]+):(.+)/', $result, $matches, PREG_SET_ORDER);
|
preg_match_all('/([\w-._]+):([^:]+):([0-9]+):(.+)/', $result, $matches, PREG_SET_ORDER);
|
||||||
|
|
||||||
$data['branch'] = $matches[0][1];
|
$data['branch'] = $matches[0][1];
|
||||||
$data['file'] = $matches[0][2];
|
$data['file'] = $matches[0][2];
|
||||||
$data['line'] = $matches[0][3];
|
$data['line'] = $matches[0][3];
|
||||||
$data['match'] = $matches[0][4];
|
$data['match'] = $matches[0][4];
|
||||||
|
|
||||||
$searchResults[] = $data;
|
$searchResults[] = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
{% if commits %}
|
||||||
{% for date, commit in commits %}
|
{% for date, commit in commits %}
|
||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -19,6 +20,9 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
<p>No results found.</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if page != 'searchcommits' %}
|
{% if page != 'searchcommits' %}
|
||||||
<ul class="pager">
|
<ul class="pager">
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
{% block title %}GitList{% endblock %}
|
{% block title %}GitList{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% include 'breadcrumb.twig' with {breadcrumbs: [{dir: 'Commits search results', path:''}]} %}
|
{% include 'breadcrumb.twig' with {breadcrumbs: [{dir: 'Commits search results for: ' ~ query, path:''}]} %}
|
||||||
|
|
||||||
{% include 'commits_list.twig' %}
|
{% include 'commits_list.twig' %}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user