From 2d0380834f8b779989ad1e4bb5d8b1510bbf3057 Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Sun, 2 Dec 2012 20:42:21 +0100 Subject: [PATCH 01/18] Multiple root dir's recursion. Works fine, using them per repo needs to be figured out. --- .htaccess | 2 +- boot.php | 17 ++++++++++++++++- index.php | 5 +++++ src/GitList/Config.php | 7 +++++-- src/GitList/Controller/MainController.php | 5 +++++ src/GitList/Util/Routing.php | 5 ++++- 6 files changed, 36 insertions(+), 5 deletions(-) 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..a7336b2 100644 --- a/boot.php +++ b/boot.php @@ -4,7 +4,22 @@ 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; + +$config->set('git', 'repositories', $repositories); + // Startup and configure Silex application $app = new GitList\Application($config, __DIR__); diff --git a/index.php b/index.php index 51eaaa6..76807cb 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,7 @@ "; + /** * GitList 0.3 * https://github.com/klaussilveira/gitlist @@ -16,4 +18,7 @@ require 'vendor/autoload.php'; $config = GitList\Config::fromFile('config.ini'); $app = require 'boot.php'; + +echo ""; + $app->run(); diff --git a/src/GitList/Config.php b/src/GitList/Config.php index 33d5b39..31bb07b 100644 --- a/src/GitList/Config.php +++ b/src/GitList/Config.php @@ -49,8 +49,11 @@ 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"); + foreach ( $this->get('git', 'repositories') as $dir ) { + echo $dir; + if (!$dir || !is_dir($dir)) { + die("Please, edit the config file and provide your repositories directory"); + } } } } diff --git a/src/GitList/Controller/MainController.php b/src/GitList/Controller/MainController.php index 89b6f62..b99fafd 100644 --- a/src/GitList/Controller/MainController.php +++ b/src/GitList/Controller/MainController.php @@ -13,6 +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']); @@ -20,6 +21,9 @@ class MainController implements ControllerProviderInterface }, $app['git']->getRepositories($app['git.repos']) ); +*/ + + $repositories = $app['git']->getRepositories($app['git.repos']); return $app['twig']->render('index.twig', array( 'repositories' => $repositories, @@ -27,6 +31,7 @@ class MainController implements ControllerProviderInterface })->bind('homepage'); $route->get('{repo}/stats/{branch}', function($repo, $branch) use ($app) { + #$repository = $app['git']->getRepository($app['git.repos'][$repo]); $repository = $app['git']->getRepository($app['git.repos'] . $repo); $stats = $repository->getStatistics($branch); $authors = $repository->getAuthorStatistics(); diff --git a/src/GitList/Util/Routing.php b/src/GitList/Util/Routing.php index 884e251..f729435 100644 --- a/src/GitList/Util/Routing.php +++ b/src/GitList/Util/Routing.php @@ -20,8 +20,11 @@ class Routing if ($regex === null) { $app = $this->app; $quotedPaths = array_map( + #function ($repo) use ($app) { + # return preg_quote($app['util.routing']->getRelativePath($repo['path']), '#'); + #}, function ($repo) use ($app) { - return preg_quote($app['util.routing']->getRelativePath($repo['path']), '#'); + return $repo['path']; }, $this->app['git']->getRepositories($this->app['git.repos']) ); From 875d3c96619627c015478da3ddd4fa2921da6cb5 Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Mon, 3 Dec 2012 08:26:04 +0100 Subject: [PATCH 02/18] Figured out how use repository hash. Not fully implemented. --- boot.php | 4 +++- src/GitList/Application.php | 10 +++++++++- src/GitList/Controller/CommitController.php | 9 ++++++++- src/GitList/Controller/MainController.php | 22 +++++++++++++++++++-- src/GitList/Controller/TreeController.php | 13 +++++++++--- src/GitList/Git/Client.php | 2 ++ src/GitList/Util/Repository.php | 4 ++-- src/GitList/Util/Routing.php | 3 ++- views/index.twig | 4 ++-- 9 files changed, 58 insertions(+), 13 deletions(-) diff --git a/boot.php b/boot.php index a7336b2..ab4ac76 100644 --- a/boot.php +++ b/boot.php @@ -18,16 +18,18 @@ foreach( $repositories as $repo ) { } $repositories = $tmp_arr; -$config->set('git', 'repositories', $repositories); // 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/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/Controller/CommitController.php b/src/GitList/Controller/CommitController.php index 776f669..fd76805 100644 --- a/src/GitList/Controller/CommitController.php +++ b/src/GitList/Controller/CommitController.php @@ -13,7 +13,14 @@ 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); + #$repository = $app['git']->getRepository($app['git.repos'] . $repo); + + # NOTE: this call is to the ONE Client! + $repositories = $app['git']->getRepositories($app['git.repos']); + $path = $repositories[ $repo ]['path']; + + # NOTE: this call is to the OTHER Client! + $repository = $app['git']->getRepository($path); 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 b99fafd..6bb5969 100644 --- a/src/GitList/Controller/MainController.php +++ b/src/GitList/Controller/MainController.php @@ -24,6 +24,9 @@ class MainController implements ControllerProviderInterface */ $repositories = $app['git']->getRepositories($app['git.repos']); +echo "Doing that\n"; + #$repositories = $app['git.repos']; +print_r( $repositories ); return $app['twig']->render('index.twig', array( 'repositories' => $repositories, @@ -32,7 +35,14 @@ class MainController implements ControllerProviderInterface $route->get('{repo}/stats/{branch}', function($repo, $branch) use ($app) { #$repository = $app['git']->getRepository($app['git.repos'][$repo]); - $repository = $app['git']->getRepository($app['git.repos'] . $repo); + + # NOTE: this call is to the ONE Client! + $repositories = $app['git']->getRepositories($app['git.repos']); + $path = $repositories[ $repo ]['path']; + + # NOTE: this call is to the OTHER Client! + $repository = $app['git']->getRepository($path); + $stats = $repository->getStatistics($branch); $authors = $repository->getAuthorStatistics(); @@ -50,7 +60,15 @@ class MainController implements ControllerProviderInterface ->bind('stats'); $route->get('{repo}/{branch}/rss/', function($repo, $branch) use ($app) { - $repository = $app['git']->getRepository($app['git.repos'] . $repo); + #$repository = $app['git']->getRepository($app['git.repos'] ); + + # NOTE: this call is to the ONE Client! + $repositories = $app['git']->getRepositories($app['git.repos']); + $path = $repositories[ $repo ]['path']; + + # NOTE: this call is to the OTHER Client! + $repository = $app['git']->getRepository($path); + $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..1f50197 100644 --- a/src/GitList/Controller/TreeController.php +++ b/src/GitList/Controller/TreeController.php @@ -14,7 +14,14 @@ 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); + + # NOTE: this call is to the ONE Client! + $repositories = $app['git']->getRepositories($app['git.repos']); + $path = $repositories[ $repo ]['path']; + + # NOTE: this call is to the OTHER Client! + $repository = $app['git']->getRepository($path); + if (!$branch) { $branch = $repository->getHead(); } @@ -39,7 +46,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,7 +54,7 @@ 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']->getRepository($app['git.repos'][ $repo ]); if (!$branch) { $branch = $repository->getHead(); diff --git a/src/GitList/Git/Client.php b/src/GitList/Git/Client.php index 94d476a..8457bcf 100644 --- a/src/GitList/Git/Client.php +++ b/src/GitList/Git/Client.php @@ -31,6 +31,8 @@ class Client extends BaseClient */ public function getRepository($path) { +echo "this getRepository2\n"; + if (!file_exists($path) || !file_exists($path . '/.git/HEAD') && !file_exists($path . '/HEAD')) { throw new \RuntimeException('There is no GIT repository at ' . $path); } 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 f729435..28724e8 100644 --- a/src/GitList/Util/Routing.php +++ b/src/GitList/Util/Routing.php @@ -23,8 +23,9 @@ class Routing #function ($repo) use ($app) { # return preg_quote($app['util.routing']->getRelativePath($repo['path']), '#'); #}, + # TODO: return keys instead function ($repo) use ($app) { - return $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 }}

From b644610438debb1a4e427fdff153cb5e7dcbfebe Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Tue, 4 Dec 2012 06:29:10 +0100 Subject: [PATCH 03/18] Renamed getRepository() in gitter Client, to avoid method name collision; some code cleanup. --- index.php | 2 ++ src/GitList/Controller/MainController.php | 32 +++-------------------- src/GitList/Controller/TreeController.php | 17 ++++++------ 3 files changed, 15 insertions(+), 36 deletions(-) diff --git a/index.php b/index.php index 76807cb..be3f29f 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,6 @@ "; /** @@ -19,6 +20,7 @@ $config = GitList\Config::fromFile('config.ini'); $app = require 'boot.php'; +#WRI DEBUG echo ""; $app->run(); diff --git a/src/GitList/Controller/MainController.php b/src/GitList/Controller/MainController.php index 6bb5969..006b1fa 100644 --- a/src/GitList/Controller/MainController.php +++ b/src/GitList/Controller/MainController.php @@ -13,20 +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']); -echo "Doing that\n"; - #$repositories = $app['git.repos']; -print_r( $repositories ); return $app['twig']->render('index.twig', array( 'repositories' => $repositories, @@ -35,13 +22,8 @@ print_r( $repositories ); $route->get('{repo}/stats/{branch}', function($repo, $branch) use ($app) { #$repository = $app['git']->getRepository($app['git.repos'][$repo]); - - # NOTE: this call is to the ONE Client! - $repositories = $app['git']->getRepositories($app['git.repos']); - $path = $repositories[ $repo ]['path']; - - # NOTE: this call is to the OTHER Client! - $repository = $app['git']->getRepository($path); +echo "branches\n"; + $repository = $app['git']->getRepositoryCached($app['git.repos'], $repo); $stats = $repository->getStatistics($branch); $authors = $repository->getAuthorStatistics(); @@ -60,14 +42,8 @@ print_r( $repositories ); ->bind('stats'); $route->get('{repo}/{branch}/rss/', function($repo, $branch) use ($app) { - #$repository = $app['git']->getRepository($app['git.repos'] ); - - # NOTE: this call is to the ONE Client! - $repositories = $app['git']->getRepositories($app['git.repos']); - $path = $repositories[ $repo ]['path']; - - # NOTE: this call is to the OTHER Client! - $repository = $app['git']->getRepository($path); +echo "rss\n"; + $repository = $app['git']->getRepositoryCached($app['git.repos'], $repo); $commits = $repository->getPaginatedCommits($branch); diff --git a/src/GitList/Controller/TreeController.php b/src/GitList/Controller/TreeController.php index 1f50197..9d0efa4 100644 --- a/src/GitList/Controller/TreeController.php +++ b/src/GitList/Controller/TreeController.php @@ -15,12 +15,7 @@ class TreeController implements ControllerProviderInterface $route->get('{repo}/tree/{branch}/{tree}/', $treeController = function($repo, $branch = '', $tree = '') use ($app) { - # NOTE: this call is to the ONE Client! - $repositories = $app['git']->getRepositories($app['git.repos']); - $path = $repositories[ $repo ]['path']; - - # NOTE: this call is to the OTHER Client! - $repository = $app['git']->getRepository($path); + $repository = $app['git']->getRepositoryCached($app['git.repos'], $repo); if (!$branch) { $branch = $repository->getHead(); @@ -54,8 +49,12 @@ 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 ]); +echo "searc\n"; + $repository = $app['git']->getRepositoryCached($app['git.repos'], $repo); + $path = $repository->getPath(); + + $repository = $app['git']->getRepository($path ); if (!$branch) { $branch = $repository->getHead(); } @@ -88,7 +87,9 @@ class TreeController implements ControllerProviderInterface ->bind('repository'); $route->get('{repo}/{format}ball/{branch}', function($repo, $format, $branch) use ($app) { - $repository = $app['git']->getRepository($app['git.repos'] . $repo); + $repository = $app['git']->getRepositoryCached($app['git.repos'], $repo); + $path = $repository->getPath(); + $tree = $repository->getBranchTree($branch); if (false === $tree) { From eb9e660f5bf62f6914b83ec2e17a652d035ab392 Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Tue, 4 Dec 2012 07:06:43 +0100 Subject: [PATCH 04/18] Code for loading repo in TreeController. --- src/GitList/Controller/TreeController.php | 33 ++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/GitList/Controller/TreeController.php b/src/GitList/Controller/TreeController.php index 9d0efa4..97a10a6 100644 --- a/src/GitList/Controller/TreeController.php +++ b/src/GitList/Controller/TreeController.php @@ -75,20 +75,16 @@ echo "searc\n"; ->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']->getRepositoryCached($app['git.repos'], $repo); - $path = $repository->getPath(); +echo "tarball\n"; + + $repo_item = $app['git']->getRepositoryCached($app['git.repos'], $repo); + $path = $repo_item->getPath(); + + $repository = $app['git']->getRepository($path ); $tree = $repository->getBranchTree($branch); @@ -120,6 +116,19 @@ echo "searc\n"; ->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; } } From ccdee643c6fa3e05dbf9e5426bfcc34b8783fd1c Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Thu, 20 Dec 2012 20:56:10 +0100 Subject: [PATCH 05/18] multiple dir's fully tested. --- config.ini-example | 6 ++++++ index.php | 6 ------ src/GitList/Config.php | 16 ++++++++++++++-- src/GitList/Controller/BlobController.php | 7 +++++-- src/GitList/Controller/CommitController.php | 21 ++++++++++----------- src/GitList/Controller/MainController.php | 10 +++++----- src/GitList/Controller/TreeController.php | 3 --- src/GitList/Git/Client.php | 2 -- 8 files changed, 40 insertions(+), 31 deletions(-) diff --git a/config.ini-example b/config.ini-example index 70815f7..ce7571a 100644 --- a/config.ini-example +++ b/config.ini-example @@ -2,6 +2,12 @@ client = '/usr/bin/git' ; Your git executable path repositories = '/var/www/projects/' ; 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 be3f29f..0f46386 100644 --- a/index.php +++ b/index.php @@ -1,8 +1,5 @@ "; - /** * GitList 0.3 * https://github.com/klaussilveira/gitlist @@ -20,7 +17,4 @@ $config = GitList\Config::fromFile('config.ini'); $app = require 'boot.php'; -#WRI DEBUG -echo ""; - $app->run(); diff --git a/src/GitList/Config.php b/src/GitList/Config.php index 31bb07b..d7710b4 100644 --- a/src/GitList/Config.php +++ b/src/GitList/Config.php @@ -49,11 +49,23 @@ class Config protected function validateOptions() { + $at_least_one_ok = false; + $at_least_one_wrong = false; + foreach ( $this->get('git', 'repositories') as $dir ) { - echo $dir; if (!$dir || !is_dir($dir)) { - die("Please, edit the config file and provide your repositories directory"); + $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 fd76805..ae10b6b 100644 --- a/src/GitList/Controller/CommitController.php +++ b/src/GitList/Controller/CommitController.php @@ -13,14 +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); - - # NOTE: this call is to the ONE Client! - $repositories = $app['git']->getRepositories($app['git.repos']); - $path = $repositories[ $repo ]['path']; - - # NOTE: this call is to the OTHER Client! - $repository = $app['git']->getRepository($path); + $repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo); + $repository = $app['git']->getRepository($repotmp->getPath()); list($branch, $file) = $app['util.repository']->extractRef($repository, $branch, $file); @@ -53,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) { @@ -74,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( @@ -87,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 006b1fa..d7f0b05 100644 --- a/src/GitList/Controller/MainController.php +++ b/src/GitList/Controller/MainController.php @@ -21,9 +21,9 @@ class MainController implements ControllerProviderInterface })->bind('homepage'); $route->get('{repo}/stats/{branch}', function($repo, $branch) use ($app) { - #$repository = $app['git']->getRepository($app['git.repos'][$repo]); -echo "branches\n"; - $repository = $app['git']->getRepositoryCached($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(); @@ -42,8 +42,8 @@ echo "branches\n"; ->bind('stats'); $route->get('{repo}/{branch}/rss/', function($repo, $branch) use ($app) { -echo "rss\n"; - $repository = $app['git']->getRepositoryCached($app['git.repos'], $repo); + $repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo); + $repository = $app['git']->getRepository($repotmp->getPath()); $commits = $repository->getPaginatedCommits($branch); diff --git a/src/GitList/Controller/TreeController.php b/src/GitList/Controller/TreeController.php index 97a10a6..7b92548 100644 --- a/src/GitList/Controller/TreeController.php +++ b/src/GitList/Controller/TreeController.php @@ -49,7 +49,6 @@ class TreeController implements ControllerProviderInterface ->bind('tree'); $route->post('{repo}/tree/{branch}/search', function(Request $request, $repo, $branch = '', $tree = '') use ($app) { -echo "searc\n"; $repository = $app['git']->getRepositoryCached($app['git.repos'], $repo); $path = $repository->getPath(); @@ -79,8 +78,6 @@ echo "searc\n"; # 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) { -echo "tarball\n"; - $repo_item = $app['git']->getRepositoryCached($app['git.repos'], $repo); $path = $repo_item->getPath(); diff --git a/src/GitList/Git/Client.php b/src/GitList/Git/Client.php index 8457bcf..94d476a 100644 --- a/src/GitList/Git/Client.php +++ b/src/GitList/Git/Client.php @@ -31,8 +31,6 @@ class Client extends BaseClient */ public function getRepository($path) { -echo "this getRepository2\n"; - if (!file_exists($path) || !file_exists($path . '/.git/HEAD') && !file_exists($path . '/HEAD')) { throw new \RuntimeException('There is no GIT repository at ' . $path); } From 53326fffa7d1421af202fbc34bc8a2c19b0381c5 Mon Sep 17 00:00:00 2001 From: Toby Allen Date: Sun, 30 Dec 2012 11:06:17 +0000 Subject: [PATCH 06/18] Added base for Windows user Hint to use double quotes for Git Executible path. Set repo base to windows path. --- config.ini-example | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config.ini-example b/config.ini-example index 70815f7..a653540 100644 --- a/config.ini-example +++ b/config.ini-example @@ -2,6 +2,11 @@ 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 + + ; You can hide repositories from GitList, just copy this for each repository you want to hide ; hidden[] = '/var/www/projects/BetaTest' From c74258e7288bd64a347e330712cf059c9f129a5d Mon Sep 17 00:00:00 2001 From: Toby Allen Date: Sun, 30 Dec 2012 12:17:22 +0000 Subject: [PATCH 07/18] Changed single quote to double quote around format This is required for use on windows. --- src/GitList/Git/Repository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitList/Git/Repository.php b/src/GitList/Git/Repository.php index 4c0cf91..321fe11 100644 --- a/src/GitList/Git/Repository.php +++ b/src/GitList/Git/Repository.php @@ -18,7 +18,7 @@ class Repository extends BaseRepository { $page = 15 * $page; $pager = "--skip=$page --max-count=15"; - $command = "log $pager --pretty=format:'%H%h%T%P%an%ae%at%cn%ce%ct'"; + $command = "log $pager --pretty=format:\"%H%h%T%P%an%ae%at%cn%ce%ct\""; if ($file) { $command .= " $file"; @@ -37,7 +37,7 @@ class Repository extends BaseRepository public function searchCommitLog($query) { - $command = "log --grep='$query' --pretty=format:'%H%h%T%P%an%ae%at%cn%ce%ct'"; + $command = "log --grep='$query' --pretty=format:\"%H%h%T%P%an%ae%at%cn%ce%ct\""; $logs = $this->getPrettyFormat($command); From 6034d143461be7257c9372de3e8a33dbb8c4dbee Mon Sep 17 00:00:00 2001 From: Toby Allen Date: Sun, 30 Dec 2012 19:38:33 +0000 Subject: [PATCH 08/18] Changes to Route to work with Windows Addition of function to test which OS and replace \ with \\ on windows. --- src/GitList/Util/Routing.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/GitList/Util/Routing.php b/src/GitList/Util/Routing.php index 28724e8..ad6ce81 100644 --- a/src/GitList/Util/Routing.php +++ b/src/GitList/Util/Routing.php @@ -19,13 +19,20 @@ class Routing if ($regex === null) { $app = $this->app; + $self = $this; $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 $repo['name']; + + function ($repo) use ($app, $self) { + $repoName = $repo['name'] ; + //Windows + if ($self->OSIsWindows()){ + $repoName = str_replace('\\', '\\\\',$repoName); + } + return $repoName; }, $this->app['git']->getRepositories($this->app['git.repos']) ); @@ -35,6 +42,17 @@ class Routing return $regex; } + + public function OSIsWindows() + { + switch(PHP_OS){ + case 'WIN32': + case 'WINNT': + case 'Windows': return true; + default : return false; + } + + } /** * Strips the base path from a full repository path From 8cb0ce623ee06eadf2a1d4714f43153b3211a9cf Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Mon, 31 Dec 2012 14:44:21 +0100 Subject: [PATCH 09/18] Added storing of found repos in cache file. --- src/GitList/Application.php | 14 +++++++++----- src/GitList/Git/Client.php | 2 ++ src/GitList/Provider/GitServiceProvider.php | 3 +++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/GitList/Application.php b/src/GitList/Application.php index 353b238..df4f709 100644 --- a/src/GitList/Application.php +++ b/src/GitList/Application.php @@ -39,17 +39,20 @@ class Application extends SilexApplication )); $repositories = $config->get('git', 'repositories'); -/* - echo "doing this\n"; - $repositories = $app['git']->getRepositories($repositories); - $config->set('git', 'repositories', $repositories); -*/ + + $cached_repos = $root . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'repos.json'; $this->register(new GitServiceProvider(), array( 'git.client' => $config->get('git', 'client'), 'git.repos' => $repositories, + 'cache.repos' => $cached_repos, + 'ini.file' => "config.ini", 'git.hidden' => $config->get('git', 'hidden') ? $config->get('git', 'hidden') : array(), )); + + $cached_repos = $root . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'repos.json'; + + $this->register(new ViewUtilServiceProvider()); $this->register(new RepositoryUtilServiceProvider()); $this->register(new UrlGeneratorServiceProvider()); @@ -61,6 +64,7 @@ class Application extends SilexApplication return $twig; })); + // Handle errors $this->error(function (\Exception $e, $code) use ($app) { if ($app['debug']) { diff --git a/src/GitList/Git/Client.php b/src/GitList/Git/Client.php index 94d476a..5605dd1 100644 --- a/src/GitList/Git/Client.php +++ b/src/GitList/Git/Client.php @@ -41,4 +41,6 @@ class Client extends BaseClient return new Repository($path, $this); } + + } diff --git a/src/GitList/Provider/GitServiceProvider.php b/src/GitList/Provider/GitServiceProvider.php index 5427560..d3738c8 100644 --- a/src/GitList/Provider/GitServiceProvider.php +++ b/src/GitList/Provider/GitServiceProvider.php @@ -8,6 +8,7 @@ use Silex\ServiceProviderInterface; class GitServiceProvider implements ServiceProviderInterface { + /** * Register the Git\Client on the Application ServiceProvider * @@ -19,6 +20,8 @@ class GitServiceProvider implements ServiceProviderInterface $app['git'] = function () use ($app) { $options['path'] = $app['git.client']; $options['hidden'] = $app['git.hidden']; + $options['ini.file'] = $app['ini.file']; + $options['cache.repos'] = $app['cache.repos']; return new Client($options); }; From 3507fb454a4a10bce32761c6dcd643de8ee9af77 Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Sat, 19 Jan 2013 09:07:50 +0100 Subject: [PATCH 10/18] Merged with master main repo. --- src/GitList/Controller/CommitController.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/GitList/Controller/CommitController.php b/src/GitList/Controller/CommitController.php index 06f6441..afcd9f4 100644 --- a/src/GitList/Controller/CommitController.php +++ b/src/GitList/Controller/CommitController.php @@ -52,19 +52,13 @@ class CommitController implements ControllerProviderInterface ->value('file', '') ->bind('commits'); -<<<<<<< HEAD $route->post('{repo}/commits/search', function(Request $request, $repo) use ($app) { $repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo); $repository = $app['git']->getRepository($repotmp->getPath()); + $query = $request->get('query'); $commits = $repository->searchCommitLog($request->get('query')); -======= - $route->post('{repo}/commits/{branch}/search', function(Request $request, $repo, $branch = '') use ($app) { - $repository = $app['git']->getRepository($app['git.repos'] . $repo); - $query = $request->get('query'); - $commits = $repository->searchCommitLog($query); $categorized = array(); ->>>>>>> ab7ffc181b3d27a13e908a4e2b331a085b09f70b foreach ($commits as $commit) { $date = $commit->getDate(); From 2715c5467ae18f0175e200cbbfd4fd1f7b503b9b Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Sun, 20 Jan 2013 14:30:44 +0100 Subject: [PATCH 11/18] GitList multidir passes unit test. --- tests/InterfaceTest.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/InterfaceTest.php b/tests/InterfaceTest.php index 6d8c85e..c3bbf97 100644 --- a/tests/InterfaceTest.php +++ b/tests/InterfaceTest.php @@ -36,7 +36,8 @@ class InterfaceTest extends WebTestCase // GitTest repository fixture $git->createRepository(self::$tmpdir . 'GitTest'); - $repository = $git->getRepository(self::$tmpdir . 'GitTest'); + #$repository = $git->getRepository(self::$tmpdir . 'GitTest'); + $repository = $git->getRepositoryCached(self::$tmpdir, 'GitTest'); file_put_contents(self::$tmpdir . 'GitTest/README.md', "## GitTest\nGitTest is a *test* repository!"); file_put_contents(self::$tmpdir . 'GitTest/test.php', "setConfig('user.name', 'Luke Skywalker'); @@ -49,7 +50,9 @@ class InterfaceTest extends WebTestCase // foobar repository fixture $git->createRepository(self::$tmpdir . 'foobar'); - $repository = $git->getRepository(self::$tmpdir . '/foobar'); + #$repository = $git->getRepository(self::$tmpdir . '/foobar'); + $repository = $git->getRepositoryCached(self::$tmpdir, 'foobar'); + file_put_contents(self::$tmpdir . 'foobar/bar.json', "{\n\"name\": \"foobar\"\n}"); file_put_contents(self::$tmpdir . 'foobar/.git/description', 'This is a test repo!'); $fs->mkdir(self::$tmpdir . 'foobar/myfolder'); @@ -65,7 +68,8 @@ class InterfaceTest extends WebTestCase $nested_dir = self::$tmpdir . 'nested/'; $fs->mkdir($nested_dir); $git->createRepository($nested_dir . 'NestedRepo'); - $repository = $git->getRepository($nested_dir . '/NestedRepo'); + #$repository = $git->getRepository($nested_dir . '/NestedRepo'); + $repository = $git->getRepositoryCached($nested_dir, 'NestedRepo'); file_put_contents($nested_dir . 'NestedRepo/.git/description', 'This is a NESTED test repo!'); file_put_contents($nested_dir . 'NestedRepo/README.txt', 'NESTED TEST REPO README'); $repository->setConfig('user.name', 'Luke Skywalker'); @@ -81,7 +85,8 @@ class InterfaceTest extends WebTestCase // master-less repository fixture $git->createRepository(self::$tmpdir . 'develop'); - $repository = $git->getRepository(self::$tmpdir . '/develop'); + #$repository = $git->getRepository(self::$tmpdir . '/develop'); + $repository = $git->getRepositoryCached(self::$tmpdir, 'develop'); $repository->setConfig('user.name', 'Luke Skywalker'); $repository->setConfig('user.email', 'luke@rebel.org'); file_put_contents(self::$tmpdir . 'develop/README.md', "## develop\ndevelop is a *test* repository!"); @@ -99,6 +104,8 @@ class InterfaceTest extends WebTestCase public function createApplication() { + $config = GitList\Config::fromFile('../config.ini'); +/* $config = new \GitList\Config(array( 'git' => array( 'client' => self::$gitPath, @@ -108,6 +115,7 @@ class InterfaceTest extends WebTestCase 'debug' => true, ), )); +*/ $app = require 'boot.php'; return $app; } From fd7ad3fb7b526bc9fce5c7d4871c6ccac76a13fe Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Sun, 20 Jan 2013 15:31:36 +0100 Subject: [PATCH 12/18] Added cache refresh option --- src/GitList/Controller/MainController.php | 15 +++++++++++++++ views/navigation.twig | 1 + 2 files changed, 16 insertions(+) diff --git a/src/GitList/Controller/MainController.php b/src/GitList/Controller/MainController.php index a321691..d7d4f63 100644 --- a/src/GitList/Controller/MainController.php +++ b/src/GitList/Controller/MainController.php @@ -20,6 +20,21 @@ class MainController implements ControllerProviderInterface )); })->bind('homepage'); + + $route->get('/refresh', function() use ($app ) { + $app['git']->deleteCached(); + + # These don't work: + #echo sfContext::getInstance()->getRequest()->getReferer(); + #$app->redirect($request->attributes->get('referer')); + #$app->redirect( $app->getRequest()->getReferer() ); + + # TODO: Fix following to return to referring page + # Or get rid of hardcoded path + return $app->redirect( "/gitlist/"); + })->bind('refresh'); + + $route->get('{repo}/stats/{branch}', function($repo, $branch) use ($app) { $repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo); diff --git a/views/navigation.twig b/views/navigation.twig index eef7144..6391812 100644 --- a/views/navigation.twig +++ b/views/navigation.twig @@ -10,6 +10,7 @@