The branch, PHP_POST_RECEIVE on karma.git has been updated
       via  b841aacab5e1e9af103b1d38e11822debda5ea22 (commit)
      from  89a2d90e9e5d2e8a661b91c1fdb3f32cf2d90cdd (commit)

http://git.php.net/?p=karma.git;a=log;h=b841aacab5e1e9af103b1d38e11822debda5ea22;hp=89a2d90e9e5d2e8a661b91c1fdb3f32cf2d90cdd

Summary of changes:
 lib/Git/PostReceiveHook.php |   52 ++++++++++++++++++++++++++++++++++++------
 1 files changed, 44 insertions(+), 8 deletions(-)

-- Log ----------------------------------------
commit b841aacab5e1e9af103b1d38e11822debda5ea22
Author: Alexander Moskaliov <ir...@php.net>
Date:   Tue Mar 6 12:16:03 2012 +0400

    commit mail

diff --git a/lib/Git/PostReceiveHook.php b/lib/Git/PostReceiveHook.php
index 0530ac4..195c8c2 100644
--- a/lib/Git/PostReceiveHook.php
+++ b/lib/Git/PostReceiveHook.php
@@ -36,7 +36,8 @@ class PostReceiveHook extends ReceiveHook
     {
         $args = func_get_args();
         array_shift($args);
-        $output = shell_exec(vsprintf($cmd, $args));
+        $cmd = vsprintf($cmd, $args);
+        $output = shell_exec($cmd);
         return $output;
     }
 
@@ -53,13 +54,18 @@ class PostReceiveHook extends ReceiveHook
             }
         }
 
-        // TODO: mail per commit
-        // send mail only about new commits
-        // But for new branches we must check if this branch was
+        // TODO: For new branches we must check if this branch was
         // cloned from other branch in this push - it's especial case
         // TODO: check old post-receive for other especial cases
-    }
 
+        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);
+            }
+        }
+
+    }
 
     /*
      * Note:
@@ -122,6 +128,8 @@ class PostReceiveHook extends ReceiveHook
                 $revisions = $this->getRevisions($branch['new']. ' --not ' . 
implode(' ', $this->allBranches));
             }
 
+            $this->cacheRevisions($branch['refname'], $revisions);
+
             $message .= "--------LOG--------\n";
             foreach ($revisions as $revision) {
                 $diff = $this->execute(
@@ -136,6 +144,17 @@ class PostReceiveHook extends ReceiveHook
         $this->mail($this->emailprefix . '[push] ' . $title , $message);
     }
 
+
+    private function cacheRevisions($branchName, array $revisions)
+    {
+        //TODO: add mail order from older commit to newer
+        foreach ($revisions as $revision)
+        {
+            $this->revisions[$revision][] = $branchName;
+        }
+    }
+
+
     private function sendTagMail(array $tag)
     {
 
@@ -162,9 +181,6 @@ class PostReceiveHook extends ReceiveHook
             $message .= "Old tag sha: \n" . $tag['old'];
         }
 
-
-        // TODO: write info about tag and target
-
         $this->mail($this->emailprefix . '[push] ' . $title , $message);
     }
 
@@ -205,6 +221,26 @@ class PostReceiveHook extends ReceiveHook
     }
 
 
+    private function sendCommitMail($revision)
+    {
+        $title = "Commit " . $revision . " was added";
+        $message = $title . "\n\n";
+
+
+        $info = $this->execute('git diff-tree --stat --pretty=fuller -c %s', 
$revision);
+
+        $message .= $info ."\n\n";
+
+        $message .= "--------DIFF--------\n";
+
+        $diff = $this->execute('git diff-tree -c -p %s', $revision);
+
+        $message .= $diff ."\n\n";
+
+        $this->mail($this->emailprefix . '[commit] ' . $title , $message);
+    }
+
+
     private function mail($subject, $message) {
         $headers = array(
             'From: ' . $this->pushAuthor . '@php.net',

Thank you for your contribution.

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to