mirror of
https://github.com/klaussilveira/gitlist.git
synced 2025-11-17 19:20:56 +01:00
changes mreged from wimrijnders
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^(.*)$ /index.php [L,NC]
|
||||
RewriteRule ^(.*)$ index.php [L,NC]
|
||||
</IfModule>
|
||||
<Files config.ini>
|
||||
order allow,deny
|
||||
|
||||
19
boot.php
19
boot.php
@@ -4,15 +4,32 @@ if (!isset($config)) {
|
||||
die("No configuration object provided.");
|
||||
}
|
||||
|
||||
$config->set('git', 'repositories', rtrim($config->get('git', 'repositories'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);
|
||||
$repositories = $config->get('git', 'repositories');
|
||||
|
||||
if ( !is_array( $repositories ) ) {
|
||||
# Convert the single item to an array - this is the internal handling
|
||||
$repositories = array( $repositories );
|
||||
}
|
||||
|
||||
$tmp_arr = array();
|
||||
foreach( $repositories as $repo ) {
|
||||
$tmp = rtrim($repo, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||
$tmp_arr []= $tmp;
|
||||
}
|
||||
$repositories = $tmp_arr;
|
||||
|
||||
|
||||
|
||||
// Startup and configure Silex application
|
||||
$app = new GitList\Application($config, __DIR__);
|
||||
|
||||
|
||||
// Mount the controllers
|
||||
$app->mount('', new GitList\Controller\MainController());
|
||||
$app->mount('', new GitList\Controller\BlobController());
|
||||
$app->mount('', new GitList\Controller\CommitController());
|
||||
$app->mount('', new GitList\Controller\TreeController());
|
||||
|
||||
|
||||
|
||||
return $app;
|
||||
|
||||
@@ -2,11 +2,19 @@
|
||||
client = '/usr/bin/git' ; Your git executable path
|
||||
repositories = '/var/www/projects/' ; Path to your repositories
|
||||
|
||||
|
||||
;Windows Users
|
||||
;client = '"C:\Program Files (x86)\Git\bin\git.exe"' ; Your git executable path
|
||||
;repositories = 'C:\Path\to\Repos\' ; Path to your repositories
|
||||
|
||||
|
||||
; If you want to specify multiple paths, use the array syntax instead:
|
||||
;
|
||||
;repositories[] = '/var/www/projects/'
|
||||
;repositories[] = '/var/www/subdir/more_projects/'
|
||||
;repositories[] = '/home/user/even_more_projects/'
|
||||
|
||||
|
||||
; You can hide repositories from GitList, just copy this for each repository you want to hide
|
||||
; hidden[] = '/var/www/projects/BetaTest'
|
||||
|
||||
|
||||
@@ -16,4 +16,5 @@ require 'vendor/autoload.php';
|
||||
$config = GitList\Config::fromFile('config.ini');
|
||||
|
||||
$app = require 'boot.php';
|
||||
|
||||
$app->run();
|
||||
|
||||
@@ -37,9 +37,17 @@ class Application extends SilexApplication
|
||||
'twig.path' => $root . DIRECTORY_SEPARATOR . 'views',
|
||||
'twig.options' => array('cache' => $root . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'views'),
|
||||
));
|
||||
|
||||
$repositories = $config->get('git', 'repositories');
|
||||
/*
|
||||
echo "doing this\n";
|
||||
$repositories = $app['git']->getRepositories($repositories);
|
||||
$config->set('git', 'repositories', $repositories);
|
||||
*/
|
||||
|
||||
$this->register(new GitServiceProvider(), array(
|
||||
'git.client' => $config->get('git', 'client'),
|
||||
'git.repos' => $config->get('git', 'repositories'),
|
||||
'git.repos' => $repositories,
|
||||
'git.hidden' => $config->get('git', 'hidden') ? $config->get('git', 'hidden') : array(),
|
||||
));
|
||||
$this->register(new ViewUtilServiceProvider());
|
||||
|
||||
@@ -49,8 +49,23 @@ class Config
|
||||
|
||||
protected function validateOptions()
|
||||
{
|
||||
if (!$this->get('git', 'repositories') || !is_dir($this->get('git', 'repositories'))) {
|
||||
die("Please, edit the config file and provide your repositories directory");
|
||||
$at_least_one_ok = false;
|
||||
$at_least_one_wrong = false;
|
||||
|
||||
foreach ( $this->get('git', 'repositories') as $dir ) {
|
||||
if (!$dir || !is_dir($dir)) {
|
||||
$at_least_one_wrong = true;
|
||||
} else {
|
||||
$at_least_one_ok = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$at_least_one_ok ) {
|
||||
die("Please, edit the config file and provide your repositories directory");
|
||||
}
|
||||
|
||||
if ( $at_least_one_wrong ) {
|
||||
die("One or more of the supplied repository paths appears to be wrong. Please, check the config file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ class BlobController implements ControllerProviderInterface
|
||||
$route = $app['controllers_factory'];
|
||||
|
||||
$route->get('{repo}/blob/{branch}/{file}', function($repo, $branch, $file) use ($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
|
||||
$repository = $app['git']->getRepository($repotmp->getPath());
|
||||
list($branch, $file) = $app['util.repository']->extractRef($repository, $branch, $file);
|
||||
|
||||
$blob = $repository->getBlob("$branch:\"$file\"");
|
||||
@@ -44,7 +45,9 @@ class BlobController implements ControllerProviderInterface
|
||||
->bind('blob');
|
||||
|
||||
$route->get('{repo}/raw/{branch}/{file}', function($repo, $branch, $file) use ($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
|
||||
$repository = $app['git']->getRepository($repotmp->getPath());
|
||||
|
||||
list($branch, $file) = $app['util.repository']->extractRef($repository, $branch, $file);
|
||||
$blob = $repository->getBlob("$branch:\"$file\"")->output();
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ class CommitController implements ControllerProviderInterface
|
||||
$route = $app['controllers_factory'];
|
||||
|
||||
$route->get('{repo}/commits/{branch}/{file}', function($repo, $branch, $file) use ($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
|
||||
$repository = $app['git']->getRepository($repotmp->getPath());
|
||||
|
||||
list($branch, $file) = $app['util.repository']->extractRef($repository, $branch, $file);
|
||||
|
||||
@@ -46,7 +47,9 @@ class CommitController implements ControllerProviderInterface
|
||||
->bind('commits');
|
||||
|
||||
$route->post('{repo}/commits/search', function(Request $request, $repo) use ($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
|
||||
$repository = $app['git']->getRepository($repotmp->getPath());
|
||||
|
||||
$commits = $repository->searchCommitLog($request->get('query'));
|
||||
|
||||
foreach ($commits as $commit) {
|
||||
@@ -67,7 +70,9 @@ class CommitController implements ControllerProviderInterface
|
||||
->bind('searchcommits');
|
||||
|
||||
$route->get('{repo}/commit/{commit}/', function($repo, $commit) use ($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
|
||||
$repository = $app['git']->getRepository($repotmp->getPath());
|
||||
|
||||
$commit = $repository->getCommit($commit);
|
||||
|
||||
return $app['twig']->render('commit.twig', array(
|
||||
@@ -80,7 +85,8 @@ class CommitController implements ControllerProviderInterface
|
||||
->bind('commit');
|
||||
|
||||
$route->get('{repo}/blame/{branch}/{file}', function($repo, $branch, $file) use ($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
|
||||
$repository = $app['git']->getRepository($repotmp->getPath());
|
||||
|
||||
list($branch, $file) = $app['util.repository']->extractRef($repository, $branch, $file);
|
||||
|
||||
|
||||
@@ -13,13 +13,7 @@ class MainController implements ControllerProviderInterface
|
||||
$route = $app['controllers_factory'];
|
||||
|
||||
$route->get('/', function() use ($app) {
|
||||
$repositories = array_map(
|
||||
function ($repo) use ($app) {
|
||||
$repo['relativePath'] = $app['util.routing']->getRelativePath($repo['path']);
|
||||
return $repo;
|
||||
},
|
||||
$app['git']->getRepositories($app['git.repos'])
|
||||
);
|
||||
$repositories = $app['git']->getRepositories($app['git.repos']);
|
||||
|
||||
return $app['twig']->render('index.twig', array(
|
||||
'repositories' => $repositories,
|
||||
@@ -27,7 +21,10 @@ class MainController implements ControllerProviderInterface
|
||||
})->bind('homepage');
|
||||
|
||||
$route->get('{repo}/stats/{branch}', function($repo, $branch) use ($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
|
||||
|
||||
$repository = $app['git']->getRepository($repotmp->getPath());
|
||||
|
||||
$stats = $repository->getStatistics($branch);
|
||||
$authors = $repository->getAuthorStatistics();
|
||||
|
||||
@@ -45,7 +42,9 @@ class MainController implements ControllerProviderInterface
|
||||
->bind('stats');
|
||||
|
||||
$route->get('{repo}/{branch}/rss/', function($repo, $branch) use ($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
|
||||
$repository = $app['git']->getRepository($repotmp->getPath());
|
||||
|
||||
$commits = $repository->getPaginatedCommits($branch);
|
||||
|
||||
$html = $app['twig']->render('rss.twig', array(
|
||||
|
||||
@@ -14,7 +14,9 @@ class TreeController implements ControllerProviderInterface
|
||||
$route = $app['controllers_factory'];
|
||||
|
||||
$route->get('{repo}/tree/{branch}/{tree}/', $treeController = function($repo, $branch = '', $tree = '') use ($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
|
||||
$repository = $app['git']->getRepositoryCached($app['git.repos'], $repo);
|
||||
|
||||
if (!$branch) {
|
||||
$branch = $repository->getHead();
|
||||
}
|
||||
@@ -39,7 +41,7 @@ class TreeController implements ControllerProviderInterface
|
||||
'breadcrumbs' => $breadcrumbs,
|
||||
'branches' => $repository->getBranches(),
|
||||
'tags' => $repository->getTags(),
|
||||
'readme' => $app['util.repository']->getReadme($repo, $branch),
|
||||
'readme' => $app['util.repository']->getReadme($repository, $branch),
|
||||
));
|
||||
})->assert('repo', $app['util.routing']->getRepositoryRegex())
|
||||
->assert('branch', '[\w-._\/]+')
|
||||
@@ -47,8 +49,11 @@ class TreeController implements ControllerProviderInterface
|
||||
->bind('tree');
|
||||
|
||||
$route->post('{repo}/tree/{branch}/search', function(Request $request, $repo, $branch = '', $tree = '') use ($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
|
||||
$repository = $app['git']->getRepositoryCached($app['git.repos'], $repo);
|
||||
$path = $repository->getPath();
|
||||
|
||||
$repository = $app['git']->getRepository($path );
|
||||
if (!$branch) {
|
||||
$branch = $repository->getHead();
|
||||
}
|
||||
@@ -69,19 +74,15 @@ class TreeController implements ControllerProviderInterface
|
||||
->assert('branch', '[\w-._\/]+')
|
||||
->bind('search');
|
||||
|
||||
$route->get('{repo}/{branch}/', function($repo, $branch) use ($app, $treeController) {
|
||||
return $treeController($repo, $branch);
|
||||
})->assert('repo', $app['util.routing']->getRepositoryRegex())
|
||||
->assert('branch', '[\w-._\/]+')
|
||||
->bind('branch');
|
||||
|
||||
$route->get('{repo}/', function($repo) use ($app, $treeController) {
|
||||
return $treeController($repo);
|
||||
})->assert('repo', $app['util.routing']->getRepositoryRegex())
|
||||
->bind('repository');
|
||||
|
||||
# WRI: Changed order of this and next statement, because order
|
||||
# appears to be important, and the other statement got precedence
|
||||
$route->get('{repo}/{format}ball/{branch}', function($repo, $format, $branch) use ($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$repo_item = $app['git']->getRepositoryCached($app['git.repos'], $repo);
|
||||
$path = $repo_item->getPath();
|
||||
|
||||
$repository = $app['git']->getRepository($path );
|
||||
|
||||
$tree = $repository->getBranchTree($branch);
|
||||
|
||||
if (false === $tree) {
|
||||
@@ -112,6 +113,19 @@ class TreeController implements ControllerProviderInterface
|
||||
->assert('branch', '[\w-._\/]+')
|
||||
->bind('archive');
|
||||
|
||||
|
||||
$route->get('{repo}/{branch}/', function($repo, $branch) use ($app, $treeController) {
|
||||
return $treeController($repo, $branch);
|
||||
})->assert('repo', $app['util.routing']->getRepositoryRegex())
|
||||
->assert('branch', '[\w-._\/]+')
|
||||
->bind('branch');
|
||||
|
||||
$route->get('{repo}/', function($repo) use ($app, $treeController) {
|
||||
return $treeController($repo);
|
||||
})->assert('repo', $app['util.routing']->getRepositoryRegex())
|
||||
->bind('repository');
|
||||
|
||||
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,9 +160,9 @@ class Repository
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getReadme($repo, $branch = 'master')
|
||||
public function getReadme($repository, $branch = 'master')
|
||||
{
|
||||
$repository = $this->app['git']->getRepository($this->app['git.repos'] . $repo);
|
||||
#$repository = $this->app['git']->getRepository($this->app['git.repos'][$repo ]);
|
||||
$files = $repository->getTree($branch)->output();
|
||||
|
||||
foreach ($files as $file) {
|
||||
|
||||
@@ -20,8 +20,12 @@ class Routing
|
||||
if ($regex === null) {
|
||||
$app = $this->app;
|
||||
$quotedPaths = array_map(
|
||||
#function ($repo) use ($app) {
|
||||
# return preg_quote($app['util.routing']->getRelativePath($repo['path']), '#');
|
||||
#},
|
||||
# TODO: return keys instead
|
||||
function ($repo) use ($app) {
|
||||
return preg_quote($app['util.routing']->getRelativePath($repo['path']), '#');
|
||||
return $repo['name'];
|
||||
},
|
||||
$this->app['git']->getRepositories($this->app['git.repos'])
|
||||
);
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
{% for repository in repositories %}
|
||||
<div class="repository">
|
||||
<div class="repository-header">
|
||||
<i class="icon-folder-open icon-spaced"></i> <a href="{{ path('repository', {repo: repository.relativePath}) }}">{{ repository.name }}</a>
|
||||
<a href="{{ path('rss', {repo: repository.relativePath, branch: 'master'}) }}"><i class="rss pull-right"></i></a>
|
||||
<i class="icon-folder-open icon-spaced"></i> <a href="{{ path('repository', {repo: repository.name}) }}">{{ repository.name }}</a>
|
||||
<a href="{{ path('rss', {repo: repository.name, branch: 'master'}) }}"><i class="rss pull-right"></i></a>
|
||||
</div>
|
||||
<div class="repository-body">
|
||||
<p>{{ repository.description }}</p>
|
||||
|
||||
Reference in New Issue
Block a user