diff --git a/boot.php b/boot.php index f5c2de8..d664cda 100644 --- a/boot.php +++ b/boot.php @@ -1,5 +1,9 @@ set('git', 'repositories', rtrim($config->get('git', 'repositories'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR); diff --git a/src/GitList/Component/Git/Repository.php b/src/GitList/Component/Git/Repository.php index e29cdc8..66213e4 100644 --- a/src/GitList/Component/Git/Repository.php +++ b/src/GitList/Component/Git/Repository.php @@ -88,7 +88,7 @@ class Repository */ public function commit($message) { - $this->getClient()->run($this, "commit -m '$message'"); + $this->getClient()->run($this, "commit -m \"$message\""); return $this; } @@ -227,14 +227,12 @@ class Repository */ public function getTotalCommits($file = null) { - $command = "rev-list --all"; - - if ($file) { - $command .= " $file"; + if (WINDOWS_BUILD) { + $command = "rev-list --count --all $file"; + } else { + $command = "rev-list --all $file | wc -l"; } - $command .= " | wc -l"; - $commits = $this->getClient()->run($this, $command); return $commits; @@ -250,7 +248,7 @@ class Repository { $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"}\''; + $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"; @@ -277,7 +275,7 @@ class Repository public function getRelatedCommits($hash) { - $logs = $this->getClient()->run($this, '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"}\''); + $logs = $this->getClient()->run($this, '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\"}"'); if (empty($logs)) { throw new \RuntimeException('No commit log available'); @@ -322,7 +320,7 @@ class Repository public function getCommit($commitHash) { - $logs = $this->getClient()->run($this, 'show --pretty=format:\'{"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"}\' ' . $commitHash); + $logs = $this->getClient()->run($this, 'show --pretty=format:"{\"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\"}" ' . $commitHash); if (empty($logs)) { throw new \RuntimeException('No commit log available'); @@ -338,7 +336,7 @@ class Repository unset($logs[0]); if (empty($logs[1])) { - $logs = explode("\n", $this->getClient()->run($this, 'diff '.$commitHash.'~1..'.$commitHash)); + $logs = explode("\n", $this->getClient()->run($this, 'diff ' . $commitHash . '~1..' . $commitHash)); } // Read diff logs @@ -417,7 +415,7 @@ class Repository public function getAuthorStatistics() { - $logs = $this->getClient()->run($this, 'log --pretty=format:\'%an||%ae\' ' . $this->getHead()); + $logs = $this->getClient()->run($this, 'log --pretty=format:"%an||%ae" ' . $this->getHead()); if (empty($logs)) { throw new \RuntimeException('No statistics available'); @@ -515,7 +513,7 @@ class Repository */ public function getBranchTree($branch) { - $hash = $this->getClient()->run($this, "log --pretty='%T' --max-count=1 $branch"); + $hash = $this->getClient()->run($this, "log --pretty=\"%T\" --max-count=1 $branch"); $hash = trim($hash, "\r\n "); return $hash ? : false; diff --git a/src/GitList/Controller/BlobController.php b/src/GitList/Controller/BlobController.php index 6ad6793..035a332 100644 --- a/src/GitList/Controller/BlobController.php +++ b/src/GitList/Controller/BlobController.php @@ -15,7 +15,7 @@ class BlobController implements ControllerProviderInterface $route->get('{repo}/blob/{branch}/{file}', function($repo, $branch, $file) use ($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); - $blob = $repository->getBlob("$branch:'$file'"); + $blob = $repository->getBlob("$branch:\"$file\""); $breadcrumbs = $app['util.view']->getBreadcrumbs($file); $fileType = $app['util.repository']->getFileType($file); @@ -36,7 +36,7 @@ class BlobController implements ControllerProviderInterface $route->get('{repo}/raw/{branch}/{file}', function($repo, $branch, $file) use ($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); - $blob = $repository->getBlob("$branch:'$file'")->output(); + $blob = $repository->getBlob("$branch:\"$file\"")->output(); return new Response($blob, 200, array('Content-Type' => 'text/plain')); })->assert('file', '.+') diff --git a/src/GitList/Controller/TreeController.php b/src/GitList/Controller/TreeController.php index 7cb8ba1..c8a9708 100644 --- a/src/GitList/Controller/TreeController.php +++ b/src/GitList/Controller/TreeController.php @@ -19,7 +19,7 @@ class TreeController implements ControllerProviderInterface if (!$branch) { $branch = $repository->getHead(); } - $files = $repository->getTree($tree ? "$branch:'$tree'/" : $branch); + $files = $repository->getTree($tree ? "$branch:\"$tree\"/" : $branch); $breadcrumbs = $app['util.view']->getBreadcrumbs($tree); $parent = null; diff --git a/src/GitList/Util/Repository.php b/src/GitList/Util/Repository.php index dde5cbe..fa7c871 100644 --- a/src/GitList/Util/Repository.php +++ b/src/GitList/Util/Repository.php @@ -135,7 +135,7 @@ class Repository if (preg_match('/^readme*/i', $file['name'])) { return array( 'filename' => $file['name'], - 'content' => $repository->getBlob("$branch:'{$file['name']}'")->output() + 'content' => $repository->getBlob("$branch:\"{$file['name']}\"")->output() ); } } diff --git a/src/GitList/Util/View.php b/src/GitList/Util/View.php index e79970b..612aa04 100644 --- a/src/GitList/Util/View.php +++ b/src/GitList/Util/View.php @@ -32,6 +32,7 @@ class View { $pageNumber = (empty($pageNumber)) ? 0 : $pageNumber; $lastPage = intval($totalCommits / 15); + // If total commits are integral multiple of 15, the lastPage will be commits/15 - 1. $lastPage = ($lastPage * 15 == $totalCommits) ? $lastPage - 1 : $lastPage; $nextPage = $pageNumber + 1;