Commit: 42d233ae4752adbce2709553cef0cd456b92a2e0
Author: Alexander Moskaliov(ir...@php.net) Tue, 20 Mar 2012 10:34:35
+0400
Committer: Alexander Moskaliov(ir...@php.net) Tue, 20 Mar 2012 10:35:41
+0400
Parents: c3c822e0f983c7514f8043ec11ceeef9c80100c0
4a6cbdd7b551664f76c536fd67c009ba25c98d2d
Link:
http://git.php.net/?p=karma.git;a=commitdiff;h=42d233ae4752adbce2709553cef0cd456b92a2e0
Log:
Merge branch 'PHP_POST_RECEIVE'
Changed paths:
MM lib/Git/PostReceiveHook.php
MM lib/Git/ReceiveHook.php
42d233ae4752adbce2709553cef0cd456b92a2e0
diff --combined lib/Git/PostReceiveHook.php
index 633ff77,743b6ac..bd3be9b
--- a/lib/Git/PostReceiveHook.php
+++ b/lib/Git/PostReceiveHook.php
@@@ -17,12 -17,14 +17,14 @@@ class PostReceiveHook extends ReceiveHo
private $allBranches = [];
+ private $branchesMailIds = [];
+
/**
- * @param $basePath string base path for all repositories
- * @param $pushAuthor string user who make push
- * @param $usersFile string path to file with users data
- * @param $mailingList string mail recipient
- * @param $emailPrefix string prefix for mail subject
+ * @param string $basePath base path for all repositories
+ * @param string $pushAuthor user who make push
+ * @param string $usersFile path to file with users data
+ * @param string $mailingList mail recipient
+ * @param string $emailPrefix prefix for mail subject
*/
public function __construct($basePath, $pushAuthor, $usersFile,
$mailingList, $emailPrefix)
{
@@@ -37,73 -39,9 +39,73 @@@
$this->allBranches = $this->getAllBranches();
}
+
+ public function getReceivedMessages()
+ {
+ $this->hookInput();
+
+ $paths = array_map(
+ function ($input) {
+ return $this->getReceivedMessagesForRange($input['old'],
$input['new']);
+ },
+ $this->refs);
+
+ /* remove empty lines, and flattern the array */
+ $flattend = array_reduce($paths, 'array_merge', []);
+ $paths = array_filter($flattend);
+
+ return array_unique($paths);
+ }
+
+ /**
+ * Returns an array of commit messages between revision $old and $new.
+ *
+ * @param string $old The old revison number.
+ * @parma string $new The new revison umber.
+ *
+ * @return array
+ */
+ private function getReceivedMessagesForRange($old, $new)
+ {
+ $repourl = \Git::getRepositoryPath();
+ $output = [];
+
+ if ($old == '0000000000000000000000000000000000000000') {
+ $cmd = sprintf(
+ "%s --git-dir=%s for-each-ref --format='%%(refname)'
'refs/heads/*'",
+ self::GIT_EXECUTABLE,
+ $repourl
+ );
+ exec($cmd, $output);
+
+ /* do we have heads? otherwise it's a new repo! */
+ $heads = implode(' ', $output);
+ $not = count($output) > 0 ? sprintf('--not %s',
escapeshellarg($heads)) : '';
+ $cmd = sprintf(
+ '%s --git-dir=%s log --pretty=format:"[%%ae] %%H %%s" %s %s',
+ \Git::GIT_EXECUTABLE,
+ $repourl,
+ $not,
+ escapeshellarg($new)
+ );
+ exec($cmd, $output);
+ } else {
+ $cmd = sprintf(
+ '%s --git-dir=%s log --pretty=format:"[%%ae] %%H %%s" %s..%s',
+ \Git::GIT_EXECUTABLE,
+ $repourl,
+ escapeshellarg($old),
+ escapeshellarg($new)
+ );
+ exec($cmd, $output);
+ }
+
+ return $output;
+ }
+
/**
* Find user name by nickname in users data file
- * @param $user user nickname
+ * @param string $user user nickname
* @return string user name
*/
public function getUserName($user)
@@@ -147,7 -85,7 +149,7 @@@
if ($ref['reftype'] == self::REF_TAG) {
$this->sendTagMail($ref['refname'], $ref['changetype'],
$ref['old'], $ref['new']);
} elseif ($ref['reftype'] == self::REF_BRANCH){
- $this->sendBranchMail($ref['refname'], $ref['changetype'],
$ref['old'], $ref['new']);
+ $this->branchesMailIds[$ref['refname']] =
$this->sendBranchMail($ref['refname'], $ref['changetype'], $ref['old'],
$ref['new']);
}
}
@@@ -155,12 -93,11 +157,11 @@@
foreach ($this->revisions as $revision => $branches) {
// check if it commit was already in other branches
if (!$this->isRevExistsInBranches($revision,
array_diff($this->allBranches, $branches))) {
- $this->sendCommitMail($revision);
+ $this->sendCommitMail($revision, $branches);
}
}
}
-
/**
* Send mail about branch.
* Subject: [git] [branch] %PROJECT%: %STATUS% branch %BRANCH_NAME%
@@@ -183,15 -120,15 +184,16 @@@
*
* --/part1--
*
- * @param $name string branch fullname (refs/heads/example)
- * @param $changeType int delete, create or update
- * @param $oldrev string old revision
- * @param $newrev string new revision
+ * @param string $name branch fullname (refs/heads/example)
+ * @param int $changeType delete, create or update
+ * @param string $oldrev old revision
+ * @param string $newrev new revision
+ * @return string mail uniq id
*/
private function sendBranchMail($name, $changeType, $oldrev, $newrev)
{
+ $logString = '';
$status = [self::TYPE_UPDATED => 'update', self::TYPE_CREATED =>
'create', self::TYPE_DELETED => 'delete'];
$shortname = str_replace('refs/heads/', '', $name);
@@@ -227,7 -164,7 +229,7 @@@
$mail = new \Mail();
- $mail->setSubject($this->emailPrefix . '[branch] ' .
$this->getRepositoryName() . ': ' . $status[$changeType] . ' branch ' .
$shortname);
+ $mail->setSubject($this->emailPrefix . ' branch ' .
$this->getRepositoryName() . ': ' . $status[$changeType] . ' branch ' .
$shortname);
$message = 'Branch ' . $shortname . ' in ' .
$this->getRepositoryName() . ' was ' . $status[$changeType] . 'd' . "\n";
$message .= 'Date: ' . date('r') . "\n";
@@@ -267,12 -204,13 +269,13 @@@
$mail->send();
+ return $mail->getId();
}
/**
* Cache revisions per branche for use it later
- * @param $branchName string branch fullname
+ * @param string $branchName branch fullname
* @param array $revisions revisions array
*/
private function cacheRevisions($branchName, array $revisions)
@@@ -310,10 -248,10 +313,10 @@@
* %PATHS%
* --/part1--
*
- * @param $name string tag fullname (refs/tags/example)
- * @param $changeType int delete, create or update
- * @param $oldrev string old revision
- * @param $newrev string new revision
+ * @param string $name tag fullname (refs/tags/example)
+ * @param int $changeType delete, create or update
+ * @param string $oldrev old revision
+ * @param string $newrev new revision
*/
private function sendTagMail($name, $changeType, $oldrev, $newrev)
{
@@@ -321,7 -259,7 +324,7 @@@
$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";
@@@ -386,7 -324,7 +389,7 @@@
* only for annotated tag:
* 'tagger', 'tagger_email', 'tagger_date' - info about tagger person
* 'log' - tag message
- * @param $tag string tag fullname
+ * @param string $tag tag fullname
* @return array array with tag info
*/
private function getTagInfo($tag)
@@@ -416,10 -354,10 +419,10 @@@
/**
* Find revisions for branch change
* Also cache revisions list for revisions mails
- * @param $name string branch fullname (refs/heads/example)
- * @param $changeType int delete, create or update
- * @param $oldrev string old revision
- * @param $newrev string new revision
+ * @param string $name branch fullname (refs/heads/example)
+ * @param int $changeType delete, create or update
+ * @param string $oldrev old revision
+ * @param string $newrev new revision
* @return array revisions list
*/
private function getBranchRevisions($name, $changeType, $oldrev, $newrev)
@@@ -453,7 -391,7 +456,7 @@@
*
* Required already escaped string in $revRange!!!
*
- * @param $revRange string A..B or A ^B C --not D etc.
+ * @param string $revRange A..B or A ^B C --not D etc.
* @return array revsions list
*/
private function getRevisions($revRange)
@@@ -477,7 -415,7 +480,7 @@@
* 'log' - full commit message
*
* Also cache revision info
- * @param $revision revision
+ * @param string $revision revision
* @return array commit info array
*/
private function getCommitInfo($revision)
@@@ -494,7 -432,7 +497,7 @@@
'committer_email' => $raw[6], // %ce
'committer_date' => $raw[7], // %cD
'subject' => $raw[8], // %s
- 'log' => $raw[9]
+ 'log' => $raw[9] // %B
];
}
return $this->commitsData[$revision];
@@@ -502,7 -440,7 +505,7 @@@
/**
* Find info about bugs in log message
- * @param $log log message
+ * @param string $log log message
* @return array array with bug numbers and links in values
*/
private function getBugs($log)
@@@ -548,9 -486,10 +551,10 @@@
* %DIFF%
* --/part2--
*
- * @param $revision string commit revision
+ * @param string $revision commit revision
+ * @param array $branches branches in current push with this commit
*/
- private function sendCommitMail($revision)
+ private function sendCommitMail($revision, $branches)
{
$info = $this->getCommitInfo($revision);
@@@ -563,7 -502,7 +567,7 @@@
$diff = \Git::gitExec('diff-tree -c -p %s',
escapeshellarg($revision));
$mail = new \Mail();
- $mail->setSubject($this->emailPrefix . '[commit] ' .
$this->getRepositoryName() . ': ' . implode(' ', array_keys($paths)));
+ $mail->setSubject($this->emailPrefix . ' commit ' .
$this->getRepositoryName() . ': ' . implode(' ', array_keys($paths)));
$message = '';
@@@ -621,13 -560,19 +625,19 @@@
$mail->setFrom($this->pushAuthor . '@php.net', $this->pushAuthorName);
$mail->addTo($this->mailingList);
+ foreach ($branches as $branch) {
+ if (isset($this->branchesMailIds[$branch])) {
+ $mail->addReplyTo($this->branchesMailIds[$branch]);
+ }
+ }
+
$mail->send();
}
/**
* Check if revision exists in branches list
- * @param $revision string revision
+ * @param string $revision revision
* @param array $branches branches
* @return bool
*/
diff --combined lib/Git/ReceiveHook.php
index db607a7,72a51b5..b526e9a
--- a/lib/Git/ReceiveHook.php
+++ b/lib/Git/ReceiveHook.php
@@@ -16,7 -16,7 +16,7 @@@ abstract class ReceiveHoo
protected $refs = [];
/**
- * @param $basePath Base path for all repositories
+ * @param string $basePath Base path for all repositories
*/
public function __construct($basePath)
{
@@@ -28,10 -28,10 +28,10 @@@
/**
* Escape array items by escapeshellarg function
- * @param $args
+ * @param array $args
* @return array array with escaped items
*/
- protected function escapeArrayShellArgs($args)
+ protected function escapeArrayShellArgs(array $args)
{
return array_map('escapeshellarg', $args);
}
@@@ -57,7 -57,7 +57,7 @@@
*
* Required already escaped string in $revRange!!!
*
- * @param $revRange
+ * @param string $revRange
* @return array
*/
protected function getChangedPaths($revRange)
@@@ -140,7 -140,5 +140,7 @@@
}
}
$this->refs = $parsed_input;
+ return $this->refs;
}
+
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php