Refactored away getRepositoryCached() in gitlist.

This commit is contained in:
Wim Rijnders
2013-04-03 10:23:44 +02:00
parent dcd701faf9
commit b07897f098
5 changed files with 17 additions and 29 deletions

View File

@@ -13,9 +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\"");
@@ -46,8 +45,7 @@ class BlobController implements ControllerProviderInterface
->bind('blob');
$route->get('{repo}/raw/{branch}/{file}', function($repo, $branch, $file) use ($app) {
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
$repository = $app['git']->getRepository($repotmp->getPath());
$repository = $app['git']->getRepository($app['git.repos'], $repo);
list($branch, $file) = $app['util.repository']->extractRef($repository, $branch, $file);
$blob = $repository->getBlob("$branch:\"$file\"")->output();

View File

@@ -13,9 +13,7 @@ class CommitController implements ControllerProviderInterface
$route = $app['controllers_factory'];
$route->get('{repo}/commits/{branch}/{file}', function($repo, $branch, $file) use ($app) {
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
$repository = $app['git']->getRepository($repotmp->getPath());
$repository = $app['git']->getRepository($app['git.repos'], $repo);
if ($branch === null) {
$branch = $repository->getHead();
@@ -54,8 +52,7 @@ class CommitController implements ControllerProviderInterface
->bind('commits');
$route->post('{repo}/commits/{branch}/search', function(Request $request, $repo, $branch) use ($app) {
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
$repository = $app['git']->getRepository($repotmp->getPath());
$repository = $app['git']->getRepository($app['git.repos'], $repo);
$query = $request->get('query');
$commits = $repository->searchCommitLog($request->get('query'));
@@ -81,8 +78,7 @@ class CommitController implements ControllerProviderInterface
->bind('searchcommits');
$route->get('{repo}/commit/{commit}/', function($repo, $commit) use ($app) {
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
$repository = $app['git']->getRepository($repotmp->getPath());
$repository = $app['git']->getRepository($app['git.repos'], $repo);
$commit = $repository->getCommit($commit);
$branch = $repository->getHead();
@@ -98,8 +94,7 @@ class CommitController implements ControllerProviderInterface
$route->get('{repo}/blame/{branch}/{file}', function($repo, $branch, $file) use ($app) {
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
$repository = $app['git']->getRepository($repotmp->getPath());
$repository = $app['git']->getRepository($app['git.repos'], $repo);
list($branch, $file) = $app['util.repository']->extractRef($repository, $branch, $file);

View File

@@ -31,9 +31,7 @@ class MainController implements ControllerProviderInterface
$route->get('{repo}/stats/{branch}', function($repo, $branch) use ($app) {
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
$repository = $app['git']->getRepository($repotmp->getPath());
$repository = $app['git']->getRepository($app['git.repos'], $repo);
if ($branch === null) {
$branch = $repository->getHead();
@@ -56,8 +54,7 @@ class MainController implements ControllerProviderInterface
->bind('stats');
$route->get('{repo}/{branch}/rss/', function($repo, $branch) use ($app) {
$repotmp = $app['git']->getRepositoryCached($app['git.repos'], $repo);
$repository = $app['git']->getRepository($repotmp->getPath());
$repository = $app['git']->getRepository($app['git.repos'], $repo);
$commits = $repository->getPaginatedCommits($branch);

View File

@@ -54,10 +54,7 @@ class TreeController implements ControllerProviderInterface
$route->post('{repo}/tree/{branch}/search',
function(Request $request, $repo, $branch = '', $tree = '') use ($app) {
$repository = $app['git']->getRepositoryCached($app['git.repos'], $repo);
$path = $repository->getPath();
$repository = $app['git']->getRepository($path);
$repository = $app['git']->getRepository($app['git.repos'], $repo);
if (!$branch) {
$branch = $repository->getHead();
}
@@ -83,10 +80,7 @@ class TreeController implements ControllerProviderInterface
# 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) {
$repo_item = $app['git']->getRepositoryCached($app['git.repos'], $repo);
$path = $repo_item->getPath();
$repository = $app['git']->getRepository($path);
$repository = $app['git']->getRepository($app['git.repos'], $repo);
$tree = $repository->getBranchTree($branch);

View File

@@ -24,13 +24,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);
}