diff --git a/controllers/commitController.php b/controllers/commitController.php index cb98927..896b41b 100644 --- a/controllers/commitController.php +++ b/controllers/commitController.php @@ -2,7 +2,9 @@ $app->get('{repo}/commits/{branch}', function($repo, $branch) use($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); - $commits = $repository->getCommits(); + $pagenumber = $app['request']->get('page'); + $pagenumber = (empty($pagenumber)) ? 0 : $pagenumber; + $commits = $repository->getCommits(null, $pagenumber); foreach ($commits as $commit) { $date = $commit->getDate(); @@ -13,6 +15,7 @@ $app->get('{repo}/commits/{branch}', function($repo, $branch) use($app) { return $app['twig']->render('commits.twig', array( 'baseurl' => $app['baseurl'], 'page' => 'commits', + 'pagenumber' => $pagenumber, 'repo' => $repo, 'branch' => $branch, 'branches' => $repository->getBranches(), @@ -25,7 +28,9 @@ $app->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); - $commits = $repository->getCommits($file); + $pagenumber = $app['request']->get('page'); + $pagenumber = (empty($pagenumber)) ? 0 : $pagenumber; + $commits = $repository->getCommits($file, $pagenumber); foreach ($commits as $commit) { $date = $commit->getDate(); @@ -36,6 +41,7 @@ $app->get('{repo}/commits/{branch}/{file}/', function($repo, $branch, $file) use return $app['twig']->render('commits.twig', array( 'baseurl' => $app['baseurl'], 'page' => 'commits', + 'pagenumber' => $pagenumber, 'repo' => $repo, 'branch' => $branch, 'branches' => $repository->getBranches(), diff --git a/index.php b/index.php index 037f878..93d12c1 100644 --- a/index.php +++ b/index.php @@ -22,7 +22,7 @@ $app['autoloader']->registerNamespace('Application', __DIR__.'/lib'); $app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => __DIR__.'/views', 'twig.class_path' => __DIR__.'/vendor', - 'twig.options' => array('cache' => __DIR__.'/cache'), +// 'twig.options' => array('cache' => __DIR__.'/cache'), )); $app->register(new Git\GitServiceProvider(), array( 'git.client' => $config['git']['client'], diff --git a/lib/Git/Repository.php b/lib/Git/Repository.php index edc9c7a..12baa85 100644 --- a/lib/Git/Repository.php +++ b/lib/Git/Repository.php @@ -222,15 +222,22 @@ class Repository * @access public * @return array Commit log */ - public function getCommits($file = null) + public function getCommits($file = null, $page = 0) { - $command = 'log --pretty=format:\'"%h": {"hash": "%H", "short_hash": "%h", "tree": "%T", "parent": "%P", "author": "%an", "author_email": "%ae", "date": "%at", "commiter": "%cn", "commiter_email": "%ce", "commiter_date": "%ct", "message": "%f"}\''; + $page = 15 * $page; + $pager = "--skip=$page --max-count=15"; + $command = 'log ' . $pager . ' --pretty=format:\'"%h": {"hash": "%H", "short_hash": "%h", "tree": "%T", "parent": "%P", "author": "%an", "author_email": "%ae", "date": "%at", "commiter": "%cn", "commiter_email": "%ce", "commiter_date": "%ct", "message": "%f"}\''; if ($file) { $command .= " $file"; } $logs = $this->getClient()->run($this, $command); + + if (empty($logs)) { + throw new \RuntimeException('No commit log available'); + } + $logs = str_replace("\n", ',', $logs); $logs = json_decode("{ $logs }", true); diff --git a/views/commits.twig b/views/commits.twig index 9f794f0..e1daff0 100644 --- a/views/commits.twig +++ b/views/commits.twig @@ -39,6 +39,17 @@ {% endfor %} +
+