Permalink
Browse files

many bugfixes

  • Loading branch information...
1 parent 99a863d commit cffd3b39b05fae71090586fcc9f717f857c20ae0 Alexander Moskaliov committed Mar 14, 2012
File renamed without changes.
@@ -8,19 +8,21 @@ namespace Karma;
// TODO: documentation
-// /git/users.db
-
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set('UTC');
putenv("PATH=/opt/bin:/usr/local/bin:/usr/bin:/bin");
putenv("LC_ALL=en_US.UTF-8");
mb_internal_encoding("UTF-8");
const REPOSITORY_PATH = '/git/repositories';
+const LIB_PATH = '/git/checkout/karma/lib';
+const USERS_DB_FILE = '/git/users.db';
+
+set_include_path(
+ getenv('KARMA_LIB_PATH') ?: LIB_PATH .
+ PATH_SEPARATOR .
+ get_include_path());
-set_include_path('/git/checkout/karma/lib' .
- PATH_SEPARATOR .
- get_include_path());
include 'Mail.php';
include 'Git.php';
@@ -39,5 +41,11 @@ if (getenv('REMOTE_USER')) {
$user = getenv('GL_USER');
}
-$hook = new \Git\PostReceiveHook(getenv('GL_REPO_BASE_ABS') ?: REPOSITORY_PATH, $user, $recipients, $emailPrefix);
+$hook = new \Git\PostReceiveHook(
+ getenv('GL_REPO_BASE_ABS') ?: REPOSITORY_PATH,
+ $user,
+ getenv('USERS_DB_FILE') ?: USERS_DB_FILE,
+ $recipients,
+ $emailPrefix
+);
$hook->process();
View
@@ -40,7 +40,6 @@ public static function gitExec($cmd)
array_shift($args);
$cmd = vsprintf($cmd, $args);
$output = shell_exec($cmd);
- if ($output === NULL) throw new \Exception('Failed to call git');
- return $output;
+ return (string)$output;
}
}
@@ -3,12 +3,12 @@
class PostReceiveHook extends ReceiveHook
{
- const USERS_DB_FILE = '/git/users.db';
private $pushAuthor = '';
private $pushAuthorName = '';
private $mailingList = '';
private $emailPrefix = '';
+ private $usersFile = '';
private $alreadyExistsBranches = [];
private $updatedBranches = [];
@@ -20,13 +20,15 @@ class PostReceiveHook extends ReceiveHook
/**
* @param $basePath string
* @param $pushAuthor string
+ * @param $usersFile string
* @param $mailingList string
* @param $emailPrefix string
*/
- public function __construct($basePath, $pushAuthor, $mailingList, $emailPrefix)
+ public function __construct($basePath, $pushAuthor, $usersFile, $mailingList, $emailPrefix)
{
parent::__construct($basePath);
+ $this->usersFile = $usersFile;
$this->pushAuthor = $pushAuthor;
$this->pushAuthorName = $this->getUserName($pushAuthor);
$this->mailingList = $mailingList;
@@ -37,7 +39,7 @@ public function __construct($basePath, $pushAuthor, $mailingList, $emailPrefix)
public function getUserName($user)
{
- $usersDB = file(__DIR__ . '/users.db');
+ $usersDB = file($this->usersFile);
foreach ($usersDB as $userline) {
list ($username, $fullname, $email) = explode(":", trim($userline));
if ($username === $user) {
@@ -79,7 +81,7 @@ public function process()
}
// sort revisions by commit time
- usort($this->revisions, function($a, $b){
+ uksort($this->revisions, function($a, $b){
if ($a['time'] == $b['time']) {
return 0;
}
@@ -126,7 +128,7 @@ public function process()
private function sendBranchMail($name, $changeType, $oldrev, $newrev)
{
- $status = [self::TYPE_UPDATED => 'Update', self::TYPE_CREATED => 'Create', => self::TYPE_DELETED => 'Delete'];
+ $status = [self::TYPE_UPDATED => 'update', self::TYPE_CREATED => 'create', self::TYPE_DELETED => 'delete'];
$shortname = str_replace('refs/heads/', '', $name);
// forced push
@@ -149,8 +151,8 @@ private function sendBranchMail($name, $changeType, $oldrev, $newrev)
$logString .= 'Commit: ' . $revision . "\n";
$logString .= 'Author: ' . $commitInfo['author'] . '(' . $commitInfo['author_email'] . ') ' . $commitInfo['author_date'] . "\n";
$logString .= 'Committer: ' . $commitInfo['committer'] . '(' . $commitInfo['committer_email'] . ') ' . $commitInfo['committer_date'] . "\n";
- $logString .= "Link: http://git.php.net/?p=" . $this->getRepositoryName() . ".git;a=commitdiff;h=" . $revision . "\n";
- $logString .= "Shortlog:\n" . $commitInfo['subject'] . "\n";
+ $logString .= "Link: http://git.php.net/?p=" . $this->getRepositoryName() . ";a=commitdiff;h=" . $revision . "\n";
+ $logString .= "Shortlog: " . $commitInfo['subject'] . "\n";
}
}
@@ -166,7 +168,7 @@ private function sendBranchMail($name, $changeType, $oldrev, $newrev)
$message .= 'Date: ' . date('r') . "\n";
$message .= "\n";
- $message .= "Link: http://git.php.net/?p=" . $this->getRepositoryName() . ".git;a=log;h=" . $newrev . ";hp=" . $oldrev . "\n";
+ $message .= "Link: http://git.php.net/?p=" . $this->getRepositoryName() . ";a=log;h=" . $newrev . ";hp=" . $oldrev . "\n";
$message .= "\n";
// forced push
@@ -178,15 +180,15 @@ private function sendBranchMail($name, $changeType, $oldrev, $newrev)
if (strlen($logString) < 8192) {
// inline log
- $message .= "Log:\n" . $logString . "\n";
+ $message .= "\nLog:\n" . $logString . "\n";
} else {
// log attach
$logFile = 'log_' . $oldrev . '_' . $newrev . '.txt';
$mail->addTextFile($logFile, $logString);
if ((strlen($message) + $mail->getFileLength($logFile)) > 262144) {
// changed paths attach exceeded max size
$mail->dropFile($logFile);
- $message .= 'Log: <changed paths exceeded maximum size>';
+ $message .= "\nLog: <changed paths exceeded maximum size>";
}
}
}
@@ -248,10 +250,10 @@ private function cacheRevisions($branchName, array $revisions)
private function sendTagMail($name, $changeType, $oldrev, $newrev)
{
- $status = [self::TYPE_UPDATED => 'Update', self::TYPE_CREATED => 'Create', => self::TYPE_DELETED => 'Delete'];
+ $status = [self::TYPE_UPDATED => 'update', self::TYPE_CREATED => 'create', self::TYPE_DELETED => 'delete'];
$shortname = str_replace('refs/tags/', '', $name);
$mail = new \Mail();
- $mail->setSubject($this->emailPrefix . '[tag] ' . $this->getRepositoryName() . ': ' . $status[$changeType] . ' tag ' . $shortname;
+ $mail->setSubject($this->emailPrefix . '[tag] ' . $this->getRepositoryName() . ': ' . $status[$changeType] . ' tag ' . $shortname);
$message = 'Tag ' . $shortname . ' in ' . $this->getRepositoryName() . ' was ' . $status[$changeType] . 'd' .
(($changeType != self::TYPE_CREATED) ? ' from ' . $oldrev : '' ) . "\n";
@@ -269,31 +271,32 @@ private function sendTagMail($name, $changeType, $oldrev, $newrev)
if ($info['annotated']) {
$message .= 'Tag: ' . $info['revision'] . "\n";
$message .= 'Tagger: ' . $info['tagger'] . '(' . $info['tagger_email'] . ') ' . $info['tagger_date'] . "\n";
+ $message .= "Log:\n" . $info['log'] . "\n";
}
$message .= "\n";
- $message .= "Link: http://git.php.net/?p=" . $this->getRepositoryName() . ".git;a=tag;h=" . $info['revision'] . "\n";
+ $message .= "Link: http://git.php.net/?p=" . $this->getRepositoryName() . ";a=tag;h=" . $info['revision'] . "\n";
$message .= "\n";
$message .= 'Target: ' . $info['target'] . "\n";
$message .= 'Author: ' . $targetInfo['author'] . '(' . $targetInfo['author_email'] . ') ' . $targetInfo['author_date'] . "\n";
$message .= 'Committer: ' . $targetInfo['committer'] . '(' . $targetInfo['committer_email'] . ') ' . $targetInfo['committer_date'] . "\n";
if ($targetInfo['parents']) $message .= 'Parents: ' . $targetInfo['parents'] . "\n";
- $message .= "Target link: http://git.php.net/?p=" . $this->getRepositoryName() . ".git;a=commitdiff;h=" . $info['target'] . "\n";
+ $message .= "Target link: http://git.php.net/?p=" . $this->getRepositoryName() . ";a=commitdiff;h=" . $info['target'] . "\n";
$message .= "Target log:\n" . $targetInfo['log'] . "\n";
if (strlen($pathsString) < 8192) {
// inline changed paths
- $message .= "Changed paths:\n" . $pathsString . "\n";
+ $message .= "\nChanged paths:\n" . $pathsString . "\n";
} else {
// changed paths attach
$pathsFile = 'paths_' . $info['target'] . '.txt';
$mail->addTextFile($pathsFile, $pathsString);
if ((strlen($message) + $mail->getFileLength($pathsFile)) > 262144) {
// changed paths attach exceeded max size
$mail->dropFile($pathsFile);
- $message .= 'Changed paths: <changed paths exceeded maximum size>';
+ $message .= "\nChanged paths: <changed paths exceeded maximum size>";
}
}
}
@@ -312,8 +315,8 @@ private function sendTagMail($name, $changeType, $oldrev, $newrev)
*/
private function getTagInfo($tag)
{
- $temp = \Git::gitExec("for-each-ref --format=\"%%(objecttype)\n%%(*objectname)\n%%(taggername)\n%%(taggeremail)\n%%(taggerdate)\n%%(*objectname)\n%%(contents)\" %s", escapeshellarg($tag));
- $temp = explode("\n", $temp, 6); //6 elements separated by \n, last element - log message
+ $temp = \Git::gitExec("for-each-ref --format=\"%%(objecttype)\n%%(objectname)\n%%(taggername)\n%%(taggeremail)\n%%(taggerdate)\n%%(*objectname)\n%%(contents)\" %s", escapeshellarg($tag));
+ $temp = explode("\n", trim($temp), 7); //6 elements separated by \n, last element - log message
if ($temp[0] == 'tag') {
$info = [
'annotated' => true,
@@ -384,7 +387,7 @@ private function getCommitInfo($revision)
{
if (!isset($this->commitsData[$revision])) {
$raw = \Git::gitExec('rev-list -n 1 --format="%%P%%n%%an%%n%%ae%%n%%aD%%n%%cn%%n%%ce%%n%%cD%%n%%s%%n%%B" %s', escapeshellarg($revision));
- $raw = explode("\n", $raw, 9); //9 elements separated by \n, last element - log message, first(skipped) element - "commit sha"
+ $raw = explode("\n", trim($raw), 10); //10 elements separated by \n, last element - log message, first(skipped) element - "commit sha"
$this->commitsData[$revision] = [
'parents' => $raw[1], // %P
'author' => $raw[2], // %an
@@ -468,7 +471,7 @@ private function sendCommitMail($revision)
$message .= 'Committer: ' . $info['committer'] . '(' . $info['committer_email'] . ') ' . $info['committer_date'] . "\n";
if ($info['parents']) $message .= 'Parents: ' . $info['parents'] . "\n";
- $message .= "\n" . "Link: http://git.php.net/?p=" . $this->getRepositoryName() . ".git;a=commitdiff;h=" . $revision . "\n";
+ $message .= "\n" . "Link: http://git.php.net/?p=" . $this->getRepositoryName() . ";a=commitdiff;h=" . $revision . "\n";
$message .= "\nLog:\n" . $info['log'] . "\n";
@@ -479,18 +482,18 @@ private function sendCommitMail($revision)
if (strlen($pathsString) < 8192) {
// inline changed paths
- $message .= "Changed paths:\n" . $pathsString . "\n";
+ $message .= "\nChanged paths:\n" . $pathsString . "\n";
if ((strlen($pathsString) + strlen($diff)) < 8192) {
// inline diff
- $message .= "Diff:\n" . $diff . "\n";
+ $message .= "\nDiff:\n" . $diff . "\n";
} else {
// diff attach
$diffFile = 'diff_' . $revision . '.txt';
$mail->addTextFile($diffFile, $diff);
if ((strlen($message) + $mail->getFileLength($diffFile)) > 262144) {
// diff attach exceeded max size
$mail->dropFile($diffFile);
- $message .= 'Diff: <Diff exceeded maximum size>';
+ $message .= "\nDiff: <Diff exceeded maximum size>";
}
}
} else {
@@ -500,7 +503,7 @@ private function sendCommitMail($revision)
if ((strlen($message) + $mail->getFileLength($pathsFile)) > 262144) {
// changed paths attach exceeded max size
$mail->dropFile($pathsFile);
- $message .= 'Changed paths: <changed paths exceeded maximum size>';
+ $message .= "\nChanged paths: <changed paths exceeded maximum size>";
} else {
// diff attach
$diffFile = 'diff_' . $revision . '.txt';
@@ -19,7 +19,7 @@ public function __construct($karma_file, $base_path)
*/
public function isKarmaIgnored()
{
- return 'true' === \Git::gitExec('%s config karma.ignored');
+ return 'true' === \Git::gitExec('config karma.ignored');
}
public function mapInput(callable $fn) {
@@ -77,7 +77,7 @@ protected function getChangedPaths($revRange)
*/
protected function getAllBranches()
{
- $branches = explode("\n", \Git::gitExec('for-each-ref --format="%%(refname)" "refs/heads/*"'));
+ $branches = explode("\n", trim(\Git::gitExec('for-each-ref --format="%%(refname)" "refs/heads/*"')));
if ($branches[0] == '') $branches = [];
return $branches;
}

0 comments on commit cffd3b3

Please sign in to comment.