[PHP-CVS] [git] commit karma.git: lib/Git/PostReceiveHook.php lib/Git/ReceiveHook.php
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 == '') { +$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]
[PHP-CVS] [git] commit karma.git: lib/Git/PostReceiveHook.php lib/Git/ReceiveHook.php lib/Mail.php
Commit: 4a6cbdd7b551664f76c536fd67c009ba25c98d2d Author: Alexander Moskaliov(ir...@php.net) Sun, 18 Mar 2012 19:43:31 +0400 Committer: Alexander Moskaliov(ir...@php.net) Sun, 18 Mar 2012 19:43:31 +0400 Parents: 7c4de5d5a9e10eb0322d87e69f07e32ad843de60 Link: http://git.php.net/?p=karma.git;a=commitdiff;h=4a6cbdd7b551664f76c536fd67c009ba25c98d2d Log: add in-reply-to test support and fix phpdoc Changed paths: M lib/Git/PostReceiveHook.php M lib/Git/ReceiveHook.php M lib/Mail.php 4a6cbdd7b551664f76c536fd67c009ba25c98d2d diff --git a/lib/Git/PostReceiveHook.php b/lib/Git/PostReceiveHook.php index 5955bc2..743b6ac 100644 --- a/lib/Git/PostReceiveHook.php +++ b/lib/Git/PostReceiveHook.php @@ -17,12 +17,14 @@ class PostReceiveHook extends ReceiveHook 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) { @@ -39,7 +41,7 @@ class PostReceiveHook extends ReceiveHook /** * 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) @@ -83,7 +85,7 @@ class PostReceiveHook extends ReceiveHook 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']); } } @@ -91,12 +93,11 @@ class PostReceiveHook extends ReceiveHook 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% @@ -119,10 +120,11 @@ class PostReceiveHook extends ReceiveHook * * --/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) { @@ -202,12 +204,13 @@ class PostReceiveHook extends ReceiveHook $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) @@ -245,10 +248,10 @@ class PostReceiveHook extends ReceiveHook * %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 +324,7 @@ class PostReceiveHook extends ReceiveHook * 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) @@ -351,10 +354,10 @@ class