The branch PHP_POST_RECEIVE on karma.git has been updated via e41adefbee4ab8758d42a360eeaecd5e22bb7e30 (commit) from 46adcc9c1571d5a20660ca49b2762189a1495786 (commit)
http://git.php.net/?p=karma.git;a=log;h=e41adefbee4ab8758d42a360eeaecd5e22bb7e30;hp=46adcc9c1571d5a20660ca49b2762189a1495786 Summary of changes: README.POST_RECEIVE | 12 +++++++++++- hooks/post-receive | 1 - lib/Git/PostReceiveHook.php | 38 +++++++++++++++++++++++++++----------- lib/Git/ReceiveHook.php | 2 +- 4 files changed, 39 insertions(+), 14 deletions(-) -- Log ---------------------------------------- commit e41adefbee4ab8758d42a360eeaecd5e22bb7e30 Author: Alexander Moskaliov <ir...@php.net> Date: Thu Mar 8 13:40:36 2012 +0400 add few situations diff --git a/README.POST_RECEIVE b/README.POST_RECEIVE index 522ff1f..e26720f 100644 --- a/README.POST_RECEIVE +++ b/README.POST_RECEIVE @@ -16,7 +16,7 @@ This part contains info only about mail per branch. For mail per commit logic di \ 3 - B (pushed) - We get all commits reachable from new branche and not from all other branches: + We get all commits reachable from new branch and not from all other NOT NEW branches: git rev-list B --not A -> 3-B @@ -42,6 +42,16 @@ This part contains info only about mail per branch. For mail per commit logic di Now we send mail with 5-B commits only. + 1 - 2 - 3 - A (already on server or pushed) + \ + 4 - 5 - B (pushed) + \ + 6 - C (pushed) + + If we use git rev-list B --not A C we skip 4-5 revisions in B. + So we use git rev-list B --not A. See first situation in "New branch" section. + + Deleted branch (O..0): diff --git a/hooks/post-receive b/hooks/post-receive index 5576fe4..56b583b 100755 --- a/hooks/post-receive +++ b/hooks/post-receive @@ -4,7 +4,6 @@ namespace Karma; // STATUS: not worked // TODO: add license -// TODO: mails per commit // TODO: refactor with lib/Git // TODO: documentation // TODO: refactor for PHP 5.4 diff --git a/lib/Git/PostReceiveHook.php b/lib/Git/PostReceiveHook.php index c515358..a5da8ef 100644 --- a/lib/Git/PostReceiveHook.php +++ b/lib/Git/PostReceiveHook.php @@ -6,22 +6,24 @@ class PostReceiveHook extends ReceiveHook private $pushAuthor = ''; private $mailingList = ''; - private $emailprefix = ''; + private $emailPrefix = ''; private $refs = array(); + private $newBranches = array(); + private $updatedBranches = array(); private $revisions = array(); private $allBranches = array(); - public function __construct($basePath, $pushAuthor, $mailingList, $emailprefix) + public function __construct($basePath, $pushAuthor, $mailingList, $emailPrefix) { parent::__construct($basePath); $this->pushAuthor = $pushAuthor; $this->mailingList = $mailingList; - $this->emailprefix = $emailprefix; + $this->emailPrefix = $emailPrefix; $this->allBranches = $this->getAllBranches(); } @@ -45,6 +47,17 @@ class PostReceiveHook extends ReceiveHook { $this->refs = $this->hookInput(); + //cache list of new and updated branches + foreach ($this->refs as $ref) { + if ($ref['reftype'] == self::REF_BRANCH){ + if ($ref['changetype'] == self::TYPE_UPDATED) { + $this->updatedBranches[] = $ref['refname']; + } elseif ($ref['changetype'] == self::TYPE_CREATED) { + $this->newBranches[] = $ref['refname']; + } + } + } + //send mails per ref push foreach ($this->refs as $ref) { if ($ref['reftype'] == self::REF_TAG) { @@ -54,9 +67,6 @@ class PostReceiveHook extends ReceiveHook } } - // TODO: For new branches we must check if this branch was - // cloned from other branch in this push - it's especial case - foreach ($this->revisions as $revision => $branches) { // check if it commit was already in other branches if (!$this->isRevExistsInBranches($revision, array_diff($this->allBranches, $branches))) { @@ -92,7 +102,13 @@ class PostReceiveHook extends ReceiveHook } else { // for new branch we write log about new commits only - $revisions = $this->getRevisions($branch['new']. ' --not ' . implode(' ', $this->allBranches)); + $revisions = $this->getRevisions($branch['new']. ' --not ' . implode(' ', array_diff($this->allBranches, $this->newBranches))); + + foreach ($this->updatedBranches as $refname) { + if ($this->isRevExistsInBranches($this->refs[$refname]['old'], array($branch['refname']))) { + $this->cacheRevisions($branch['refname'], $this->getRevisions($this->refs[$refname]['old'] . '..' . $branch['new'])); + } + } } $this->cacheRevisions($branch['refname'], $revisions); @@ -110,7 +126,7 @@ class PostReceiveHook extends ReceiveHook } } - $this->mail($this->emailprefix . '[push] ' . $title , $message); + $this->mail($this->emailPrefix . '[push] ' . $title , $message); } @@ -119,7 +135,7 @@ class PostReceiveHook extends ReceiveHook //TODO: add mail order from older commit to newer foreach ($revisions as $revision) { - $this->revisions[$revision][] = $branchName; + $this->revisions[$revision][$branchName] = $branchName; } } @@ -150,7 +166,7 @@ class PostReceiveHook extends ReceiveHook $message .= "Old tag sha: \n" . $tag['old']; } - $this->mail($this->emailprefix . '[push] ' . $title , $message); + $this->mail($this->emailPrefix . '[push] ' . $title , $message); } private function getTagInfo($tag) @@ -206,7 +222,7 @@ class PostReceiveHook extends ReceiveHook $message .= $diff ."\n\n"; - $this->mail($this->emailprefix . '[commit] ' . $title , $message); + $this->mail($this->emailPrefix . '[commit] ' . $title , $message); } diff --git a/lib/Git/ReceiveHook.php b/lib/Git/ReceiveHook.php index f332f71..f957fc7 100644 --- a/lib/Git/ReceiveHook.php +++ b/lib/Git/ReceiveHook.php @@ -85,7 +85,7 @@ abstract class ReceiveHook } - $parsed_input[] = $ref; + $parsed_input[$ref['refname']] = $ref; } } return $parsed_input; Thank you for your contribution. -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php