diff --git a/composer.json b/composer.json
index 4cf0bc0..f14c110 100644
--- a/composer.json
+++ b/composer.json
@@ -1,8 +1,10 @@
{
"require": {
"silex/silex": "1.0.*",
- "twig/twig": "1.8.*"
- },
+ "twig/twig": "1.8.*",
+ "symfony/twig-bridge": "2.1.*"
+ },
+ "minimum-stability": "dev",
"autoload": {
"psr-0": {
"Application": "lib/",
diff --git a/composer.lock b/composer.lock
index 40dda12..0b528b5 100644
--- a/composer.lock
+++ b/composer.lock
@@ -1,5 +1,5 @@
{
- "hash": "3a86b6a3e837b125e3cebc503fd8cf38",
+ "hash": "8909d5f3ac695303e7845fe5cb0658ad",
"packages": [
{
"package": "pimple/pimple",
@@ -22,8 +22,8 @@
{
"package": "silex/silex",
"version": "dev-master",
- "source-reference": "13eb2ba916e39d5b8b1d054aaa441cf8e1004d85",
- "commit-date": "1341343086"
+ "source-reference": "23dc19c334e2f74ec4de037568f5426bceaff421",
+ "commit-date": "1341597562"
},
{
"package": "symfony/event-dispatcher",
@@ -74,16 +74,20 @@
"commit-date": "1341312726"
},
{
- "package": "twig/twig",
+ "package": "symfony/twig-bridge",
"version": "dev-master",
- "alias-pretty-version": "1.8.x-dev",
- "alias-version": "1.8.9999999.9999999-dev"
+ "alias-pretty-version": "2.1.x-dev",
+ "alias-version": "2.1.9999999.9999999-dev"
+ },
+ {
+ "package": "symfony/twig-bridge",
+ "version": "dev-master",
+ "source-reference": "2a577b6cf0fe32f383acf4a972c1d5d8f48ae1e2",
+ "commit-date": "1340549862"
},
{
"package": "twig/twig",
- "version": "dev-master",
- "source-reference": "73da773aaad0f97f2e967ec8241b8adf7b1e03d2",
- "commit-date": "1340890758"
+ "version": "v1.8.3"
}
],
"packages-dev": null,
diff --git a/config.ini-example b/config.ini-example
index fc99be3..9ae80ef 100644
--- a/config.ini-example
+++ b/config.ini-example
@@ -6,7 +6,6 @@ repositories = '/var/www/projects/' ; Path to your repositories
; hidden[] = '/var/www/projects/BetaTest'
[app]
-baseurl = 'http://localhost/git' ; Base URL of the application
; If you need to specify custom filetypes for certain extensions, do this here
[filetypes]
diff --git a/controllers/blobController.php b/controllers/blobController.php
index 822fbed..7c6b06c 100644
--- a/controllers/blobController.php
+++ b/controllers/blobController.php
@@ -1,14 +1,12 @@
get('{repo}/blob/{branch}/{file}/', function($repo, $branch, $file) use($app) {
+$app->get('{repo}/blob/{branch}/{file}', function($repo, $branch, $file) use($app) {
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
$blob = $repository->getBlob("$branch:'$file'");
- $breadcrumbs = $app['utils']->getBreadcrumbs("$repo/tree/$branch/$file");
+ $breadcrumbs = $app['utils']->getBreadcrumbs($file);
$fileType = $app['utils']->getFileType($file);
return $app['twig']->render('file.twig', array(
- 'baseurl' => $app['baseurl'],
- 'page' => 'files',
'file' => $file,
'fileType' => $fileType,
'blob' => $blob->output(),
@@ -20,7 +18,8 @@ $app->get('{repo}/blob/{branch}/{file}/', function($repo, $branch, $file) use($a
));
})->assert('file', '.+')
->assert('repo', '[\w-._]+')
- ->assert('branch', '[\w-._]+');
+ ->assert('branch', '[\w-._]+')
+ ->bind('blob');
$app->get('{repo}/raw/{branch}/{file}', function($repo, $branch, $file) use($app) {
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
@@ -29,4 +28,5 @@ $app->get('{repo}/raw/{branch}/{file}', function($repo, $branch, $file) use($app
return new Symfony\Component\HttpFoundation\Response($blob, 200, array('Content-Type' => 'text/plain'));
})->assert('file', '.+')
->assert('repo', '[\w-._]+')
- ->assert('branch', '[\w-._]+');
+ ->assert('branch', '[\w-._]+')
+ ->bind('blob_raw');
diff --git a/controllers/commitController.php b/controllers/commitController.php
index 0427c68..e861e1d 100644
--- a/controllers/commitController.php
+++ b/controllers/commitController.php
@@ -1,9 +1,10 @@
get('{repo}/commits/{branch}', function($repo, $branch) use($app) {
+$app->get('{repo}/commits/{branch}/{file}', function($repo, $branch, $file) use($app) {
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
- $pager = $app['utils']->getPager($app['request']->get('page'), $repository->getTotalCommits());
- $commits = $repository->getCommits($branch, $pager['current']);
+ $type = $file ? "$branch -- $file" : $branch;
+ $pager = $app['utils']->getPager($app['request']->get('page'), $repository->getTotalCommits($type));
+ $commits = $repository->getCommits($type, $pager['current']);
foreach ($commits as $commit) {
$date = $commit->getDate();
@@ -12,65 +13,39 @@ $app->get('{repo}/commits/{branch}', function($repo, $branch) use($app) {
}
return $app['twig']->render('commits.twig', array(
- 'baseurl' => $app['baseurl'],
- 'page' => 'commits',
'pager' => $pager,
'repo' => $repo,
'branch' => $branch,
'branches' => $repository->getBranches(),
'tags' => $repository->getTags(),
'commits' => $categorized,
+ 'file' => $file,
));
})->assert('repo', '[\w-._]+')
->assert('branch', '[\w-._]+')
- ->value('branch', 'master');
-
-$app->get('{repo}/commits/{branch}/{file}/', function($repo, $branch, $file) use($app) {
- $repository = $app['git']->getRepository($app['git.repos'] . $repo);
- $pager = $app['utils']->getPager($app['request']->get('page'), $repository->getTotalCommits("$branch -- $file"));
- $commits = $repository->getCommits("$branch -- $file", $pager['current']);
-
- foreach ($commits as $commit) {
- $date = $commit->getDate();
- $date = $date->format('m/d/Y');
- $categorized[$date][] = $commit;
- }
-
- return $app['twig']->render('commits.twig', array(
- 'baseurl' => $app['baseurl'],
- 'page' => 'commits',
- 'pager' => $pager,
- 'repo' => $repo,
- 'branch' => $branch,
- 'branches' => $repository->getBranches(),
- 'tags' => $repository->getTags(),
- 'commits' => $categorized,
- ));
-})->assert('repo', '[\w-._]+')
->assert('file', '.+')
- ->assert('branch', '[\w-._]+');
+ ->value('branch', 'master')
+ ->value('file', '')
+ ->bind('commits');
$app->get('{repo}/commit/{commit}/', function($repo, $commit) use($app) {
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
$commit = $repository->getCommit($commit);
return $app['twig']->render('commit.twig', array(
- 'baseurl' => $app['baseurl'],
- 'page' => 'commits',
'branch' => 'master',
'repo' => $repo,
'commit' => $commit,
));
})->assert('repo', '[\w-._]+')
- ->assert('commit', '[a-f0-9]+');
+ ->assert('commit', '[a-f0-9]+')
+ ->bind('commit');
-$app->get('{repo}/blame/{branch}/{file}/', function($repo, $branch, $file) use($app) {
+$app->get('{repo}/blame/{branch}/{file}', function($repo, $branch, $file) use($app) {
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
$blames = $repository->getBlame("$branch -- $file");
return $app['twig']->render('blame.twig', array(
- 'baseurl' => $app['baseurl'],
- 'page' => 'commits',
'file' => $file,
'repo' => $repo,
'branch' => $branch,
@@ -80,4 +55,5 @@ $app->get('{repo}/blame/{branch}/{file}/', function($repo, $branch, $file) use($
));
})->assert('repo', '[\w-._]+')
->assert('file', '.+')
- ->assert('branch', '[\w-._]+');
+ ->assert('branch', '[\w-._]+')
+ ->bind('blame');
diff --git a/controllers/indexController.php b/controllers/indexController.php
index df63f5b..cb85902 100644
--- a/controllers/indexController.php
+++ b/controllers/indexController.php
@@ -4,7 +4,6 @@ $app->get('/', function() use($app) {
$repositories = $app['git']->getRepositories($app['git.repos']);
return $app['twig']->render('index.twig', array(
- 'baseurl' => $app['baseurl'],
'repositories' => $repositories,
));
-});
\ No newline at end of file
+})->bind('homepage');
diff --git a/controllers/rssController.php b/controllers/rssController.php
index 55ebb29..00542eb 100644
--- a/controllers/rssController.php
+++ b/controllers/rssController.php
@@ -5,7 +5,6 @@ $app->get('{repo}/{branch}/rss/', function($repo, $branch) use($app) {
$commits = $repository->getCommits($branch);
$html = $app['twig']->render('rss.twig', array(
- 'baseurl' => $app['baseurl'],
'repo' => $repo,
'branch' => $branch,
'commits' => $commits,
@@ -13,4 +12,5 @@ $app->get('{repo}/{branch}/rss/', function($repo, $branch) use($app) {
return new Symfony\Component\HttpFoundation\Response($html, 200, array('Content-Type' => 'application/rss+xml'));
})->assert('repo', '[\w-._]+')
- ->assert('branch', '[\w-._]+');
\ No newline at end of file
+ ->assert('branch', '[\w-._]+')
+ ->bind('rss');
\ No newline at end of file
diff --git a/controllers/statsController.php b/controllers/statsController.php
index ac41f2a..666a90b 100644
--- a/controllers/statsController.php
+++ b/controllers/statsController.php
@@ -6,8 +6,6 @@ $app->get('{repo}/stats/{branch}', function($repo, $branch) use($app) {
$authors = $repository->getAuthorStatistics();
return $app['twig']->render('stats.twig', array(
- 'baseurl' => $app['baseurl'],
- 'page' => 'stats',
'repo' => $repo,
'branch' => $branch,
'branches' => $repository->getBranches(),
@@ -17,4 +15,5 @@ $app->get('{repo}/stats/{branch}', function($repo, $branch) use($app) {
));
})->assert('repo', '[\w-._]+')
->assert('branch', '[\w-._]+')
- ->value('branch', 'master');
\ No newline at end of file
+ ->value('branch', 'master')
+ ->bind('stats');
diff --git a/controllers/treeController.php b/controllers/treeController.php
index bb470cc..a3c2285 100644
--- a/controllers/treeController.php
+++ b/controllers/treeController.php
@@ -1,70 +1,43 @@
get('{repo}/', function($repo) use($app) {
+$app->get('{repo}/tree/{branch}/{tree}/', $treeController = function($repo, $branch = '', $tree = '') use($app) {
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
- $defaultBranch = $repository->getHead();
- $tree = $repository->getTree($defaultBranch);
- $breadcrumbs = $app['utils']->getBreadcrumbs("$repo/");
+ if (!$branch) {
+ $branch = $repository->getHead();
+ }
+ $files = $repository->getTree($tree ? "$branch:'$tree'/" : $branch);
+ $breadcrumbs = $app['utils']->getBreadcrumbs($tree);
+
+ $parent = null;
+ if (($slash = strrpos($tree, '/')) !== false) {
+ $parent = substr($tree, 0, $slash);
+ } elseif (!empty($tree)) {
+ $parent = '';
+ }
return $app['twig']->render('tree.twig', array(
- 'baseurl' => $app['baseurl'],
- 'page' => 'files',
- 'files' => $tree->output(),
- 'repo' => $repo,
- 'branch' => $defaultBranch,
- 'path' => '',
- 'parent' => '',
- 'breadcrumbs' => $breadcrumbs,
- 'branches' => $repository->getBranches(),
- 'tags' => $repository->getTags(),
- 'readme' => $app['utils']->getReadme($repo, $defaultBranch),
- ));
-})->assert('repo', '[\w-._]+');
-
-$app->get('{repo}/tree/{branch}/', function($repo, $branch) use($app) {
- $repository = $app['git']->getRepository($app['git.repos'] . $repo);
- $tree = $repository->getTree($branch);
- $breadcrumbs = $app['utils']->getBreadcrumbs("$repo/");
-
- return $app['twig']->render('tree.twig', array(
- 'baseurl' => $app['baseurl'],
- 'page' => 'files',
- 'files' => $tree->output(),
+ 'files' => $files->output(),
'repo' => $repo,
'branch' => $branch,
- 'path' => '',
- 'parent' => '',
+ 'path' => $tree ? $tree.'/' : $tree,
+ 'parent' => $parent,
'breadcrumbs' => $breadcrumbs,
'branches' => $repository->getBranches(),
'tags' => $repository->getTags(),
'readme' => $app['utils']->getReadme($repo, $branch),
));
})->assert('repo', '[\w-._]+')
- ->assert('branch', '[\w-._]+');
+ ->assert('branch', '[\w-._]+')
+ ->assert('tree', '.+')
+ ->bind('tree');
-$app->get('{repo}/tree/{branch}/{tree}/', function($repo, $branch, $tree) use($app) {
- $repository = $app['git']->getRepository($app['git.repos'] . $repo);
- $files = $repository->getTree("$branch:'$tree'/");
- $breadcrumbs = $app['utils']->getBreadcrumbs("$repo/tree/$branch/$tree");
+$app->get('{repo}/{branch}/', function($repo, $branch) use($app, $treeController) {
+ return $treeController($repo, $branch);
+})->assert('repo', '[\w-._]+')
+ ->assert('branch', '[\w-._]+')
+ ->bind('branch');
- if (($slash = strrpos($tree, '/')) !== false) {
- $parent = '/' . substr($tree, 0, $slash);
- } else {
- $parent = '/';
- }
-
- return $app['twig']->render('tree.twig', array(
- 'baseurl' => $app['baseurl'],
- 'page' => 'files',
- 'files' => $files->output(),
- 'repo' => $repo,
- 'branch' => $branch,
- 'path' => "$tree/",
- 'parent' => $parent,
- 'breadcrumbs' => $breadcrumbs,
- 'branches' => $repository->getBranches(),
- 'tags' => $repository->getTags(),
- ));
-})->assert('tree', '.+')
- ->assert('repo', '[\w-._]+')
- ->assert('branch', '[\w-._]+');
+$app->get('{repo}/', function($repo) use($app, $treeController) {
+ return $treeController($repo);
+})->assert('repo', '[\w-._]+')
+ ->bind('repository');
diff --git a/index.php b/index.php
index a19d943..6543e74 100644
--- a/index.php
+++ b/index.php
@@ -14,7 +14,6 @@ if (empty($config['git']['repositories']) || !is_dir($config['git']['repositorie
require 'vendor/autoload.php';
$app = new Silex\Application();
-$app['baseurl'] = rtrim($config['app']['baseurl'], '/');
$app['filetypes'] = $config['filetypes'];
$app['hidden'] = isset($config['git']['hidden']) ? $config['git']['hidden'] : array();
$config['git']['repositories'] = rtrim($config['git']['repositories'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
@@ -29,9 +28,14 @@ $app->register(new Git\GitServiceProvider(), array(
'git.repos' => $config['git']['repositories'],
));
$app->register(new Application\UtilsServiceProvider());
+$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
-// Add the md5() function to Twig scope
-$app['twig']->addFilter('md5', new Twig_Filter_Function('md5'));
+$app['twig'] = $app->share($app->extend('twig', function($twig, $app) {
+ // Add the md5() function to Twig scope
+ $twig->addFilter('md5', new Twig_Filter_Function('md5'));
+
+ return $twig;
+}));
// Load controllers
include 'controllers/indexController.php';
@@ -44,8 +48,7 @@ include 'controllers/rssController.php';
// Error handling
$app->error(function (\Exception $e, $code) use ($app) {
return $app['twig']->render('error.twig', array(
- 'baseurl' => $app['baseurl'],
- 'message' => $e->getMessage(),
+ 'message' => $e->getMessage(),
));
});
diff --git a/lib/Application/Utils.php b/lib/Application/Utils.php
index 218f4a6..9660c2e 100644
--- a/lib/Application/Utils.php
+++ b/lib/Application/Utils.php
@@ -24,21 +24,19 @@ class Utils
*/
public function getBreadcrumbs($spec)
{
+ if (!$spec) {
+ return array();
+ }
+
$paths = explode('/', $spec);
- $last = '';
- foreach ($paths as $path) {
- $dir['dir'] = $path;
- $dir['path'] = "$last/$path";
- $breadcrumbs[] = $dir;
- $last .= '/' . $path;
+ foreach ($paths as $i => $path) {
+ $breadcrumbs[] = array(
+ 'dir' => $path,
+ 'path' => implode('/', array_slice($paths, 0, $i + 1)),
+ );
}
- if (isset($paths[2])) {
- $breadcrumbs[0]['path'] .= '/' . $paths[1] . '/' . $paths[2];
- }
-
- unset($breadcrumbs[1], $breadcrumbs[2]);
return $breadcrumbs;
}
diff --git a/lib/Application/UtilsServiceProvider.php b/lib/Application/UtilsServiceProvider.php
index 0fe9642..40b19a4 100644
--- a/lib/Application/UtilsServiceProvider.php
+++ b/lib/Application/UtilsServiceProvider.php
@@ -11,13 +11,12 @@ class UtilsServiceProvider implements ServiceProviderInterface
* Register the Utils class on the Application ServiceProvider
*
* @param Application $app Silex Application
- * @return Utils Instance of the Utils class
*/
public function register(Application $app)
{
- $app['utils'] = function () use ($app) {
+ $app['utils'] = $app->share(function () use ($app) {
return new Utils($app);
- };
+ });
}
public function boot(Application $app)
diff --git a/lib/Git/Repository.php b/lib/Git/Repository.php
index cf58f96..b9fc3d4 100644
--- a/lib/Git/Repository.php
+++ b/lib/Git/Repository.php
@@ -515,7 +515,7 @@ class Repository
continue;
}
- preg_match_all("/([a-zA-Z0-9^]{8})[\s]+([0-9]+)\)(.+)/", $log, $match);
+ preg_match_all("/([a-zA-Z0-9^]{8})\s+.*?([0-9]+)\)(.+)/", $log, $match);
$current_commit = $match[1][0];
if ($current_commit != $previous_commit) {
diff --git a/views/blame.twig b/views/blame.twig
index 390053e..3cf1586 100644
--- a/views/blame.twig
+++ b/views/blame.twig
@@ -1,20 +1,11 @@
-{% extends 'layout.twig' %}
+{% extends 'layout_page.twig' %}
+
+{% set page = 'commits' %}
+
{% block title %}GitList{% endblock %}
-{% block body %}
-{% include 'navigation.twig' %}
-
-
-
-
- {% include 'menu.twig' %}
-
-
-
-
+{% block content %}
+ {% include 'breadcrumb.twig' with {breadcrumbs: [{dir: 'Blame', path:''}]} %}