diff --git a/.htaccess b/.htaccess index efb9407..cd0335e 100644 --- a/.htaccess +++ b/.htaccess @@ -3,7 +3,7 @@ RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ /index.php [L,NC] + RewriteRule ^(.*)$ index.php [L,NC] order allow,deny diff --git a/boot.php b/boot.php index 5e36efe..ab4ac76 100644 --- a/boot.php +++ b/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; diff --git a/config.ini-example b/config.ini-example index a653540..ea2c8da 100644 --- a/config.ini-example +++ b/config.ini-example @@ -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' diff --git a/index.php b/index.php index 51eaaa6..0f46386 100644 --- a/index.php +++ b/index.php @@ -16,4 +16,5 @@ require 'vendor/autoload.php'; $config = GitList\Config::fromFile('config.ini'); $app = require 'boot.php'; + $app->run(); diff --git a/src/GitList/Application.php b/src/GitList/Application.php index 7f7e2cd..353b238 100644 --- a/src/GitList/Application.php +++ b/src/GitList/Application.php @@ -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()); diff --git a/src/GitList/Config.php b/src/GitList/Config.php index 33d5b39..d7710b4 100644 --- a/src/GitList/Config.php +++ b/src/GitList/Config.php @@ -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"); + } } } diff --git a/src/GitList/Controller/BlobController.php b/src/GitList/Controller/BlobController.php index 9a44a27..e71674d 100644 --- a/src/GitList/Controller/BlobController.php +++ b/src/GitList/Controller/BlobController.php @@ -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(); diff --git a/src/GitList/Controller/CommitController.php b/src/GitList/Controller/CommitController.php index 776f669..ae10b6b 100644 --- a/src/GitList/Controller/CommitController.php +++ b/src/GitList/Controller/CommitController.php @@ -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); diff --git a/src/GitList/Controller/MainController.php b/src/GitList/Controller/MainController.php index 89b6f62..d7f0b05 100644 --- a/src/GitList/Controller/MainController.php +++ b/src/GitList/Controller/MainController.php @@ -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( diff --git a/src/GitList/Controller/TreeController.php b/src/GitList/Controller/TreeController.php index fe463b7..7b92548 100644 --- a/src/GitList/Controller/TreeController.php +++ b/src/GitList/Controller/TreeController.php @@ -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; } } diff --git a/src/GitList/Util/Repository.php b/src/GitList/Util/Repository.php index e158b95..c1ea2b7 100644 --- a/src/GitList/Util/Repository.php +++ b/src/GitList/Util/Repository.php @@ -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) { diff --git a/src/GitList/Util/Routing.php b/src/GitList/Util/Routing.php index 884e251..28724e8 100644 --- a/src/GitList/Util/Routing.php +++ b/src/GitList/Util/Routing.php @@ -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']) ); diff --git a/views/index.twig b/views/index.twig index 07093cd..db725ac 100644 --- a/views/index.twig +++ b/views/index.twig @@ -9,8 +9,8 @@ {% for repository in repositories %}

{{ repository.description }}