From b07897f098208520f8a54728959039ccfd4e312c Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Wed, 3 Apr 2013 10:23:44 +0200 Subject: [PATCH] Refactored away getRepositoryCached() in gitlist. --- src/GitList/Controller/BlobController.php | 6 ++---- src/GitList/Controller/CommitController.php | 13 ++++--------- src/GitList/Controller/MainController.php | 7 ++----- src/GitList/Controller/TreeController.php | 10 ++-------- src/GitList/Git/Client.php | 10 +++++++--- 5 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/GitList/Controller/BlobController.php b/src/GitList/Controller/BlobController.php index 9822b6e..1f923ea 100644 --- a/src/GitList/Controller/BlobController.php +++ b/src/GitList/Controller/BlobController.php @@ -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(); diff --git a/src/GitList/Controller/CommitController.php b/src/GitList/Controller/CommitController.php index 8fd3387..0fdf9ae 100644 --- a/src/GitList/Controller/CommitController.php +++ b/src/GitList/Controller/CommitController.php @@ -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); diff --git a/src/GitList/Controller/MainController.php b/src/GitList/Controller/MainController.php index 80fd7a1..1662cf7 100644 --- a/src/GitList/Controller/MainController.php +++ b/src/GitList/Controller/MainController.php @@ -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); diff --git a/src/GitList/Controller/TreeController.php b/src/GitList/Controller/TreeController.php index e9aaa19..778f1c8 100644 --- a/src/GitList/Controller/TreeController.php +++ b/src/GitList/Controller/TreeController.php @@ -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); diff --git a/src/GitList/Git/Client.php b/src/GitList/Git/Client.php index 47898b8..4f1e030 100644 --- a/src/GitList/Git/Client.php +++ b/src/GitList/Git/Client.php @@ -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); }