Windows support, fixes #26, #56 and #69

Implementing various workarounds and fixes to get GitList working fine
on Windows.
This commit is contained in:
Klaus Silveira
2012-08-17 01:59:55 -03:00
parent bf7441eea4
commit 23502ead8a
6 changed files with 20 additions and 17 deletions

View File

@@ -1,5 +1,9 @@
<?php
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
define('WINDOWS_BUILD', 1);
}
// Load configuration
$config = new GitList\Config('config.ini');
$config->set('git', 'repositories', rtrim($config->get('git', 'repositories'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);

View File

@@ -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;

View File

@@ -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', '.+')

View File

@@ -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;

View File

@@ -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()
);
}
}

View File

@@ -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;