Merge branch 'master' into search_improve

This commit is contained in:
Ilia Kondrashov
2013-05-24 21:26:50 +04:00
7 changed files with 72 additions and 52 deletions

View File

@@ -4,32 +4,17 @@ if (!isset($config)) {
die("No configuration object provided."); die("No configuration object provided.");
} }
$repositories = $config->get('git', 'repositories'); if (!is_writable(__DIR__ . DIRECTORY_SEPARATOR . 'cache')) {
die(sprintf('The "%s" folder must be writable for GitList to run.', __DIR__ . DIRECTORY_SEPARATOR . 'cache'));
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 // Startup and configure Silex application
$app = new GitList\Application($config, __DIR__); $app = new GitList\Application($config, __DIR__);
// Mount the controllers // Mount the controllers
$app->mount('', new GitList\Controller\MainController()); $app->mount('', new GitList\Controller\MainController());
$app->mount('', new GitList\Controller\BlobController()); $app->mount('', new GitList\Controller\BlobController());
$app->mount('', new GitList\Controller\CommitController()); $app->mount('', new GitList\Controller\CommitController());
$app->mount('', new GitList\Controller\TreeController()); $app->mount('', new GitList\Controller\TreeController());
return $app; return $app;

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project name="gitlist" default="build"> <project name="gitlist" default="build">
<target name="build" depends="prepare,lint,phploc,pdepend,phpmd,phpcpd,phpunit" /> <target name="build" depends="prepare,lint,phploc,pdepend,phpmd,phpcpd,phpunit,phpcs" />
<target name="build-package" depends="prepare-package,lint,phploc,package" /> <target name="build-package" depends="prepare-package,package" />
<target name="clean" description="Clean build artifacts"> <target name="clean" description="Clean build artifacts">
<delete dir="${basedir}/build"/> <delete dir="${basedir}/build"/>
@@ -10,15 +10,18 @@
<target name="prepare" depends="clean" description="Prepare for build"> <target name="prepare" depends="clean" description="Prepare for build">
<mkdir dir="${basedir}/build/logs"/> <mkdir dir="${basedir}/build/logs"/>
<mkdir dir="${basedir}/build/pdepend"/> <mkdir dir="${basedir}/build/pdepend"/>
<copy file="config.ini-example" tofile="config.ini"/>
<exec executable="composer" failonerror="true"> <exec executable="composer" failonerror="true">
<arg value="install" /> <arg value="install" />
<arg value="--dev" /> <arg value="--dev" />
</exec> </exec>
</target> </target>
<target name="prepare-package" depends="clean" description="Prepare for build"> <target name="prepare-package" description="Prepare for build">
<delete dir="${basedir}/vendor"/>
<exec executable="composer" failonerror="true"> <exec executable="composer" failonerror="true">
<arg value="install" /> <arg value="install" />
<arg value="--optimize-autoloader" />
</exec> </exec>
</target> </target>
@@ -75,15 +78,25 @@
<exec executable="phpunit" failonerror="true"/> <exec executable="phpunit" failonerror="true"/>
</target> </target>
<target name="phpcs" description="Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server">
<exec executable="phpcs" output="/dev/null">
<arg value="--report=checkstyle" />
<arg value="--report-file=${basedir}/build/logs/checkstyle.xml" />
<arg value="--standard=PSR2" />
<arg path="${basedir}/src" />
</exec>
</target>
<target name="package" description="Package the application for distribution"> <target name="package" description="Package the application for distribution">
<copy todir="${basedir}/build/gitlist/"> <copy todir="${basedir}/build/gitlist/">
<fileset dir="${basedir}" excludes="build/**, tests/**, pkg_builder/**, phpunit.xml.dist, cache.properties, .gitignore, .travis.yml, build.xml, composer.json, composer.lock, config.ini" /> <fileset dir="${basedir}" excludes="cache/**, build/**, tests/**, pkg_builder/**, phpunit.xml.dist, cache.properties, .gitignore, .travis.yml, build.xml, composer.json, composer.lock, config.ini" />
</copy> </copy>
<tar destfile="${basedir}/build/gitlist.tar.gz" <tar destfile="${basedir}/build/gitlist-master.tar.gz"
basedir="${basedir}/build/" basedir="${basedir}/build/"
compression="gzip" compression="gzip"
longfile="gnu" longfile="gnu"
excludes="gitlist-master.tar.gz, **/logs/**, **/pdepend/**"
/> />
</target> </target>
</project> </project>

View File

@@ -15,6 +15,8 @@ use GitList\Provider\RoutingUtilServiceProvider;
*/ */
class Application extends SilexApplication class Application extends SilexApplication
{ {
protected $path;
/** /**
* Constructor initialize services. * Constructor initialize services.
* *
@@ -24,44 +26,35 @@ class Application extends SilexApplication
public function __construct(Config $config, $root = null) public function __construct(Config $config, $root = null)
{ {
parent::__construct(); parent::__construct();
$app = $this; $app = $this;
$root = realpath($root); $this->path = realpath($root);
$this['debug'] = $config->get('app', 'debug'); $this['debug'] = $config->get('app', 'debug');
$this['filetypes'] = $config->getSection('filetypes'); $this['filetypes'] = $config->getSection('filetypes');
$this['cache.archives'] = $root . DIRECTORY_SEPARATOR $this['cache.archives'] = $this->getCachePath() . 'archives';
. 'cache' . DIRECTORY_SEPARATOR . 'archives';
// Register services // Register services
$this->register(new TwigServiceProvider(), array( $this->register(new TwigServiceProvider(), array(
'twig.path' => $root . DIRECTORY_SEPARATOR . 'views', 'twig.path' => $this->getViewPath(),
'twig.options' => array('cache' => $root . DIRECTORY_SEPARATOR 'twig.options' => array('cache' => $this->getCachePath() . 'views'),
. 'cache' . DIRECTORY_SEPARATOR . 'views'),
)); ));
$repositories = $config->get('git', 'repositories'); $repositories = $config->get('git', 'repositories');
$repositoryCache = $config->get('app', 'cached_repos');
$cached_repos = $config->get('app', 'cached_repos'); if (false === $repositoryCache || empty($repositoryCache)) {
if (false === $cached_repos || empty($cached_repos)) { $repositoryCache = $this->getCachePath() . 'repos.json';
$cached_repos = $root . DIRECTORY_SEPARATOR . 'cache'
. DIRECTORY_SEPARATOR . 'repos.json';
} }
$this->register(new GitServiceProvider(), array( $this->register(new GitServiceProvider(), array(
'git.client' => $config->get('git', 'client'), 'git.client' => $config->get('git', 'client'),
'git.repos' => $repositories, 'git.repos' => $repositories,
'cache.repos' => $cached_repos, 'cache.repos' => $repositoryCache,
'ini.file' => "config.ini", 'ini.file' => "config.ini",
'git.hidden' => $config->get('git', 'hidden') ? 'git.hidden' => $config->get('git', 'hidden') ?
$config->get('git', 'hidden') : array(), $config->get('git', 'hidden') : array(),
'git.default_branch' => $config->get('git', 'default_branch') ? $config->get('git', 'default_branch') : 'master', '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 ViewUtilServiceProvider());
$this->register(new RepositoryUtilServiceProvider()); $this->register(new RepositoryUtilServiceProvider());
$this->register(new UrlGeneratorServiceProvider()); $this->register(new UrlGeneratorServiceProvider());
@@ -74,7 +67,6 @@ class Application extends SilexApplication
return $twig; return $twig;
})); }));
// Handle errors // Handle errors
$this->error(function (\Exception $e, $code) use ($app) { $this->error(function (\Exception $e, $code) use ($app) {
if ($app['debug']) { if ($app['debug']) {
@@ -86,5 +78,26 @@ class Application extends SilexApplication
)); ));
}); });
} }
public function getPath()
{
return $this->path . DIRECTORY_SEPARATOR;
}
public function setPath($path)
{
$this->path = $path;
return $this;
}
public function getCachePath()
{
return $this->path . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
}
public function getViewPath()
{
return $this->path . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR;
}
} }

View File

@@ -2,4 +2,7 @@
namespace GitList\Exception; namespace GitList\Exception;
class BlankDataException extends \RuntimeException {} class BlankDataException extends \RuntimeException
{
}

View File

@@ -0,0 +1,8 @@
<?php
namespace GitList\Exception;
class EmptyRepositoryException extends \RuntimeException
{
}

View File

@@ -3,6 +3,7 @@
namespace GitList\Util; namespace GitList\Util;
use Silex\Application; use Silex\Application;
use GitList\Exception\EmptyRepositoryException;
class Routing class Routing
{ {
@@ -40,8 +41,6 @@ class Routing
} }
if ($commitish === null) { if ($commitish === null) {
// DEBUG Can you have a repo with no branches? How should we handle
// that?
$branches = $repository->getBranches(); $branches = $repository->getBranches();
$tags = $repository->getTags(); $tags = $repository->getTags();
@@ -59,11 +58,11 @@ class Routing
} }
} }
$commitish = $matchedBranch; if ($matchedBranch === null) {
throw new EmptyRepositoryException('This repository is currently empty. There are no commits.');
} }
if ($commitish === null) { $commitish = $matchedBranch;
$app->abort(404, "'$branch_path' does not appear to contain a commit-ish for '$repo'.");
} }
$commitishLength = strlen($commitish); $commitishLength = strlen($commitish);
@@ -72,11 +71,6 @@ class Routing
$path = substr($path, 1); $path = substr($path, 1);
} }
$commitHasPath = $repository->pathExists($commitish, $path);
if ($commitHasPath !== true) {
$app->abort(404, "\"$path\" does not exist in \"$commitish\".");
}
return array($commitish, $path); return array($commitish, $path);
} }

View File

@@ -17,6 +17,7 @@
{% endblock %} {% endblock %}
{% endembed %} {% endembed %}
{% if files is not empty %}
<table class="tree"> <table class="tree">
<thead> <thead>
<tr> <tr>
@@ -54,6 +55,9 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% else %}
<p>This repository is empty.</p>
{% endif %}
{% if readme is defined and readme is not empty %} {% if readme is defined and readme is not empty %}
<div class="readme-view"> <div class="readme-view">
<div class="md-header"> <div class="md-header">