diff --git a/boot.php b/boot.php
index 5e36efe..9b84f04 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 2604f89..c5f8fcb 100644
--- a/config.ini-example
+++ b/config.ini-example
@@ -3,6 +3,19 @@ client = '/usr/bin/git' ; Your git executable path
repositories = '/var/www/projects/' ; Path to your repositories
default_branch = 'master' ; Default branch when HEAD is detached
+
+;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 e6c7b6f..5d59466 100644
--- a/index.php
+++ b/index.php
@@ -10,7 +10,7 @@ if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}
-if(php_sapi_name() == 'cli-server' && file_exists(substr($_SERVER['REQUEST_URI'], 1))) {
+if (php_sapi_name() == 'cli-server' && file_exists(substr($_SERVER['REQUEST_URI'], 1))) {
return false;
}
@@ -20,4 +20,6 @@ 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 9671dd6..ced3505 100644
--- a/src/GitList/Application.php
+++ b/src/GitList/Application.php
@@ -30,19 +30,38 @@ class Application extends SilexApplication
$this['debug'] = $config->get('app', 'debug');
$this['filetypes'] = $config->getSection('filetypes');
- $this['cache.archives'] = $root . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'archives';
+ $this['cache.archives'] = $root . DIRECTORY_SEPARATOR
+ . 'cache' . DIRECTORY_SEPARATOR . 'archives';
// Register services
$this->register(new TwigServiceProvider(), array(
'twig.path' => $root . DIRECTORY_SEPARATOR . 'views',
- 'twig.options' => array('cache' => $root . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'views'),
+ 'twig.options' => array('cache' => $root . DIRECTORY_SEPARATOR
+ . 'cache' . DIRECTORY_SEPARATOR . 'views'),
));
+
+ $repositories = $config->get('git', 'repositories');
+
+ $cached_repos = $config->get('app', 'cached_repos');
+ if (false === $cached_repos || empty($cached_repos)) {
+ $cached_repos = $root . DIRECTORY_SEPARATOR . 'cache'
+ . DIRECTORY_SEPARATOR . 'repos.json';
+ }
+
$this->register(new GitServiceProvider(), array(
- 'git.client' => $config->get('git', 'client'),
- 'git.repos' => $config->get('git', 'repositories'),
- 'git.hidden' => $config->get('git', 'hidden') ? $config->get('git', 'hidden') : 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(),
'git.default_branch' => $config->get('git', 'default_branch') ? $config->get('git', 'default_branch') : 'master',
));
+
+ $cached_repos = $root . DIRECTORY_SEPARATOR .
+ 'cache' . DIRECTORY_SEPARATOR . 'repos.json';
+
+
$this->register(new ViewUtilServiceProvider());
$this->register(new RepositoryUtilServiceProvider());
$this->register(new UrlGeneratorServiceProvider());
@@ -55,6 +74,7 @@ class Application extends SilexApplication
return $twig;
}));
+
// Handle errors
$this->error(function (\Exception $e, $code) use ($app) {
if ($app['debug']) {
@@ -67,3 +87,4 @@ class Application extends SilexApplication
});
}
}
+
diff --git a/src/GitList/Config.php b/src/GitList/Config.php
index 60bbf5c..711133b 100644
--- a/src/GitList/Config.php
+++ b/src/GitList/Config.php
@@ -51,8 +51,24 @@ class Config
protected function validateOptions()
{
- if (!$this->get('git', 'repositories') || !is_dir($this->get('git', 'repositories'))) {
+ $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 a954da0..d006fe7 100644
--- a/src/GitList/Controller/BlobController.php
+++ b/src/GitList/Controller/BlobController.php
@@ -13,7 +13,7 @@ class BlobController implements ControllerProviderInterface
$route = $app['controllers_factory'];
$route->get('{repo}/blob/{commitishPath}', function ($repo, $commitishPath) use ($app) {
- $repository = $app['git']->getRepository($app['git.repos'] . $repo);
+ $repository = $app['git']->getRepository($app['git.repos'], $repo);
list($branch, $file) = $app['util.routing']
->parseCommitishPathParam($commitishPath, $repo);
@@ -47,7 +47,7 @@ class BlobController implements ControllerProviderInterface
->bind('blob');
$route->get('{repo}/raw/{commitishPath}', function ($repo, $commitishPath) use ($app) {
- $repository = $app['git']->getRepository($app['git.repos'] . $repo);
+ $repository = $app['git']->getRepository($app['git.repos'], $repo);
list($branch, $file) = $app['util.routing']
->parseCommitishPathParam($commitishPath, $repo);
@@ -73,3 +73,4 @@ class BlobController implements ControllerProviderInterface
return $route;
}
}
+
diff --git a/src/GitList/Controller/CommitController.php b/src/GitList/Controller/CommitController.php
index aaa6c85..e017160 100644
--- a/src/GitList/Controller/CommitController.php
+++ b/src/GitList/Controller/CommitController.php
@@ -13,7 +13,7 @@ class CommitController implements ControllerProviderInterface
$route = $app['controllers_factory'];
$route->get('{repo}/commits/{commitishPath}', function ($repo, $commitishPath) use ($app) {
- $repository = $app['git']->getRepository($app['git.repos'] . $repo);
+ $repository = $app['git']->getRepository($app['git.repos'], $repo);
if ($commitishPath === null) {
$commitishPath = $repository->getHead();
@@ -53,9 +53,10 @@ class CommitController implements ControllerProviderInterface
->bind('commits');
$route->post('{repo}/commits/{branch}/search', function (Request $request, $repo, $branch = '') use ($app) {
- $repository = $app['git']->getRepository($app['git.repos'] . $repo);
+ $repository = $app['git']->getRepository($app['git.repos'], $repo);
$query = $request->get('query');
- $commits = $repository->searchCommitLog($query);
+
+ $commits = $repository->searchCommitLog($request->get('query'));
$categorized = array();
foreach ($commits as $commit) {
@@ -78,7 +79,7 @@ class CommitController implements ControllerProviderInterface
->bind('searchcommits');
$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);
$branch = $repository->getHead();
@@ -92,7 +93,7 @@ class CommitController implements ControllerProviderInterface
->bind('commit');
$route->get('{repo}/blame/{commitishPath}', function ($repo, $commitishPath) use ($app) {
- $repository = $app['git']->getRepository($app['git.repos'] . $repo);
+ $repository = $app['git']->getRepository($app['git.repos'], $repo);
list($branch, $file) = $app['util.routing']
->parseCommitishPathParam($commitishPath, $repo);
@@ -116,3 +117,4 @@ class CommitController implements ControllerProviderInterface
return $route;
}
}
+
diff --git a/src/GitList/Controller/MainController.php b/src/GitList/Controller/MainController.php
index f7b5a85..58cd494 100644
--- a/src/GitList/Controller/MainController.php
+++ b/src/GitList/Controller/MainController.php
@@ -5,6 +5,7 @@ namespace GitList\Controller;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\Request;
class MainController implements ControllerProviderInterface
{
@@ -12,28 +13,30 @@ 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']);
- $repository = $app['git']->getRepository($repo['path']);
- $repo['branch'] = $repository->getHead();
-
- return $repo;
- },
- $app['git']->getRepositories($app['git.repos'])
- );
+ $route->get('/', function() use ($app) {
+ $repositories = $app['git']->getRepositories($app['git.repos']);
return $app['twig']->render('index.twig', array(
'repositories' => $repositories,
));
})->bind('homepage');
- $route->get('{repo}/stats/{branch}', function ($repo, $branch) use ($app) {
- $repository = $app['git']->getRepository($app['git.repos'] . $repo);
+
+ $route->get('/refresh', function(Request $request) use ($app ) {
+ $app['git']->deleteCached();
+
+ # Go back to calling page
+ return $app->redirect($request->headers->get('Referer'));
+ })->bind('refresh');
+
+
+ $route->get('{repo}/stats/{branch}', function($repo, $branch) use ($app) {
+ $repository = $app['git']->getRepository($app['git.repos'], $repo);
+
if ($branch === null) {
$branch = $repository->getHead();
}
+
$stats = $repository->getStatistics($branch);
$authors = $repository->getAuthorStatistics();
@@ -50,8 +53,8 @@ class MainController implements ControllerProviderInterface
->value('branch', null)
->bind('stats');
- $route->get('{repo}/{branch}/rss/', function ($repo, $branch) use ($app) {
- $repository = $app['git']->getRepository($app['git.repos'] . $repo);
+ $route->get('{repo}/{branch}/rss/', function($repo, $branch) use ($app) {
+ $repository = $app['git']->getRepository($app['git.repos'], $repo);
if ($branch === null) {
$branch = $repository->getHead();
@@ -74,3 +77,4 @@ class MainController implements ControllerProviderInterface
return $route;
}
}
+
diff --git a/src/GitList/Controller/TreeController.php b/src/GitList/Controller/TreeController.php
index f14ebf2..3a24d0d 100644
--- a/src/GitList/Controller/TreeController.php
+++ b/src/GitList/Controller/TreeController.php
@@ -14,7 +14,7 @@ class TreeController implements ControllerProviderInterface
$route = $app['controllers_factory'];
$route->get('{repo}/tree/{commitishPath}/', $treeController = function ($repo, $commitishPath = '') use ($app) {
- $repository = $app['git']->getRepository($app['git.repos'] . $repo);
+ $repository = $app['git']->getRepository($app['git.repos'], $repo);
if (!$commitishPath) {
$commitishPath = $repository->getHead();
}
@@ -41,15 +41,14 @@ 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('commitishPath', $app['util.routing']->getCommitishPathRegex())
->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();
}
@@ -71,19 +70,12 @@ class TreeController implements ControllerProviderInterface
->assert('branch', $app['util.routing']->getBranchRegex())
->bind('search');
- $route->get('{repo}/{branch}/', function ($repo, $branch) use ($app, $treeController) {
- return $treeController($repo, $branch);
- })->assert('repo', $app['util.routing']->getRepositoryRegex())
- ->assert('branch', $app['util.routing']->getBranchRegex())
- ->bind('branch');
- $route->get('{repo}/', function ($repo) use ($app, $treeController) {
- return $treeController($repo);
- })->assert('repo', $app['util.routing']->getRepositoryRegex())
- ->bind('repository');
+ # Intentionally before next statement, because order appears
+ # to be important, and the other statement got precedence previously.
+ $route->get('{repo}/{format}ball/{branch}', function($repo, $format, $branch) use ($app) {
+ $repository = $app['git']->getRepository($app['git.repos'], $repo);
- $route->get('{repo}/{format}ball/{branch}', function ($repo, $format, $branch) use ($app) {
- $repository = $app['git']->getRepository($app['git.repos'] . $repo);
$tree = $repository->getBranchTree($branch);
if (false === $tree) {
@@ -114,6 +106,19 @@ class TreeController implements ControllerProviderInterface
->assert('branch', $app['util.routing']->getBranchRegex())
->bind('archive');
+
+ $route->get('{repo}/{branch}/', function($repo, $branch) use ($app, $treeController) {
+ return $treeController($repo, $branch);
+ })->assert('repo', $app['util.routing']->getRepositoryRegex())
+ ->assert('branch', $app['util.routing']->getBranchRegex())
+ ->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/Git/Client.php b/src/GitList/Git/Client.php
index 0034f8f..4129a7b 100644
--- a/src/GitList/Git/Client.php
+++ b/src/GitList/Git/Client.php
@@ -57,13 +57,17 @@ class Client extends BaseClient
}
/**
- * Opens a repository at the specified path
+ * Opens a specified repository
*
- * @param string $path Path where the repository is located
+ * @param array $repos Array of items describing configured repositories
+ * @param string $repo Name of repository we are currently handling
* @return Repository Instance of Repository
*/
- public function getRepository($path)
+ public function getRepository($repos, $repo)
{
+ $repotmp = $this->getRepositoryCached($repos, $repo);
+ $path = $repotmp->getPath();
+
if (!file_exists($path) || !file_exists($path . '/.git/HEAD') && !file_exists($path . '/HEAD')) {
throw new \RuntimeException('There is no GIT repository at ' . $path);
}
@@ -75,3 +79,4 @@ class Client extends BaseClient
return new Repository($path, $this);
}
}
+
diff --git a/src/GitList/Git/Repository.php b/src/GitList/Git/Repository.php
index dc8eec3..65db976 100644
--- a/src/GitList/Git/Repository.php
+++ b/src/GitList/Git/Repository.php
@@ -42,7 +42,16 @@ class Repository extends BaseRepository
*/
public function getCommit($commitHash)
{
- $logs = $this->getClient()->run($this, "show --pretty=format:\"
{{ repository.description }}
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 @@