The branch PHP_POST_RECEIVE on karma.git has been updated
       via  8507e88c7abde403c9bdf1b385d5d4f2b284d1f3 (commit)
       via  509b56df21c8cd0ee971c9580adadc00379df8b1 (commit)
       via  454db4da98f95049825b3a9018542d709136a7bc (commit)
      from  e41adefbee4ab8758d42a360eeaecd5e22bb7e30 (commit)

http://git.php.net/?p=karma.git;a=log;h=8507e88c7abde403c9bdf1b385d5d4f2b284d1f3;hp=e41adefbee4ab8758d42a360eeaecd5e22bb7e30

Summary of changes:
 hooks/post-receive          |    7 +-
 lib/Git/PostReceiveHook.php |  285 +++++++++++++++++++++++++++++++++----------
 lib/Git/ReceiveHook.php     |   10 +-
 lib/Mail.php                |  169 +++++++++++++++++++++++++
 4 files changed, 398 insertions(+), 73 deletions(-)
 create mode 100644 lib/Mail.php

-- Log ----------------------------------------
commit 8507e88c7abde403c9bdf1b385d5d4f2b284d1f3
Author: Alexander Moskaliov <ir...@php.net>
Date:   Sat Mar 10 20:38:54 2012 +0400

    add Mail class and reformat commit mail

diff --git a/hooks/post-receive b/hooks/post-receive
index b05bd82..12884a4 100755
--- a/hooks/post-receive
+++ b/hooks/post-receive
@@ -10,6 +10,7 @@ namespace Karma;
 // TODO: reformat mails
 // TODO: check mail length
 
+// /git/users.db
 
 error_reporting(E_ALL | E_STRICT);
 date_default_timezone_set('UTC');
@@ -23,6 +24,7 @@ set_include_path('/git/checkout/karma/lib' .
     PATH_SEPARATOR .
     get_include_path());
 
+include 'Mail.php';
 include 'Git.php';
 include 'Git/ReceiveHook.php';
 include 'Git/PostReceiveHook.php';
diff --git a/lib/Git/PostReceiveHook.php b/lib/Git/PostReceiveHook.php
index fd8df3f..8250559 100644
--- a/lib/Git/PostReceiveHook.php
+++ b/lib/Git/PostReceiveHook.php
@@ -76,9 +76,9 @@ class PostReceiveHook extends ReceiveHook
         //send mails per ref push
         foreach ($this->refs as $ref) {
             if ($ref['reftype'] == self::REF_TAG) {
-                $this->sendTagMail($ref);
+                $this->sendTagMail($ref['refname'], $ref['changetype'], 
$ref['old'], $ref['new']);
             } elseif ($ref['reftype'] == self::REF_BRANCH){
-                $this->sendBranchMail($ref);
+                $this->sendBranchMail($ref['refname'], $ref['changetype'], 
$ref['old'], $ref['new']);
             }
         }
 
@@ -92,44 +92,47 @@ class PostReceiveHook extends ReceiveHook
     }
 
     /**
-     * @param array $branch
+     * @param $name string
+     * @param $changeType int
+     * @param $oldrev string
+     * @param $newrev string
      */
-    private function sendBranchMail(array $branch)
+    private function sendBranchMail($name, $changeType, $oldrev, $newrev)
     {
 
-        if ($branch['changetype'] == self::TYPE_UPDATED) {
-            $title = "Branch " . $branch['refname'] . " was updated";
-        } elseif ($branch['changetype'] == self::TYPE_CREATED) {
-            $title = "Branch " . $branch['refname'] . " was created";
+        if ($changeType == self::TYPE_UPDATED) {
+            $title = "Branch " . $name . " was updated";
+        } elseif ($changeType == self::TYPE_CREATED) {
+            $title = "Branch " . $name . " was created";
         } else {
-            $title = "Branch " . $branch['refname'] . " was deleted";
+            $title = "Branch " . $name . " was deleted";
         }
         $message = $title . "\n\n";
 
 
-        if ($branch['changetype'] != self::TYPE_DELETED) {
+        if ($changeType != self::TYPE_DELETED) {
 
-            if ($branch['changetype'] == self::TYPE_UPDATED) {
+            if ($changeType == self::TYPE_UPDATED) {
                 // check if push was with --force option
-                if ($replacedRevisions = $this->getRevisions($branch['new'] . 
'..' . $branch['old'])) {
+                if ($replacedRevisions = $this->getRevisions($newrev . '..' . 
$oldrev)) {
                     $message .= "Discarded revisions: \n" . implode("\n", 
$replacedRevisions) . "\n";
                 }
 
                 // git rev-list old..new
-                $revisions = $this->getRevisions($branch['old'] . '..' . 
$branch['new']);
+                $revisions = $this->getRevisions($oldrev . '..' . $newrev);
 
             } else {
                 // for new branch we write log about new commits only
-                $revisions = $this->getRevisions($branch['new']. ' --not ' . 
implode(' ', array_diff($this->allBranches, $this->newBranches)));
+                $revisions = $this->getRevisions($newrev. ' --not ' . 
implode(' ', array_diff($this->allBranches, $this->newBranches)));
 
                 foreach ($this->updatedBranches as $refname) {
-                    if 
($this->isRevExistsInBranches($this->refs[$refname]['old'],[$branch['refname']]))
 {
-                        $this->cacheRevisions($branch['refname'], 
$this->getRevisions($this->refs[$refname]['old'] . '..' . $branch['new']));
+                    if 
($this->isRevExistsInBranches($this->refs[$refname]['old'], [$name])) {
+                        $this->cacheRevisions($name, 
$this->getRevisions($this->refs[$refname]['old'] . '..' . $newrev));
                     }
                 }
             }
 
-            $this->cacheRevisions($branch['refname'], $revisions);
+            $this->cacheRevisions($name, $revisions);
 
             if (count($revisions)) {
                 $message .= "--------LOG--------\n";
@@ -163,32 +166,35 @@ class PostReceiveHook extends ReceiveHook
 
 
     /**
-     * @param array $tag
+     * @param $name string
+     * @param $changetype int
+     * @param $oldrev string
+     * @param $newrev string
      */
-    private function sendTagMail(array $tag)
+    private function sendTagMail($name, $changetype, $oldrev, $newrev)
     {
 
-        if ($tag['changetype'] == self::TYPE_UPDATED) {
-            $title = "Tag " . $tag['refname'] . " was updated";
-        } elseif ($tag['changetype'] == self::TYPE_CREATED) {
-            $title = "Tag " . $tag['refname'] . " was created";
+        if ($changetype == self::TYPE_UPDATED) {
+            $title = "Tag " . $name . " was updated";
+        } elseif ($changetype == self::TYPE_CREATED) {
+            $title = "Tag " . $name . " was created";
         } else {
-            $title = "Tag " . $tag['refname'] . " was deleted";
+            $title = "Tag " . $name . " was deleted";
         }
 
         $message = $title . "\n\n";
 
-        if ($tag['changetype'] != self::TYPE_DELETED) {
+        if ($changetype != self::TYPE_DELETED) {
             $message .= "Tag info:\n";
-            $isAnnotatedNewTag = $this->isAnnotatedTag($tag['refname']);
+            $isAnnotatedNewTag = $this->isAnnotatedTag($name);
             if ($isAnnotatedNewTag) {
-                $message .= $this->getAnnotatedTagInfo($tag['refname']) ."\n";
+                $message .= $this->getAnnotatedTagInfo($name) ."\n";
             } else {
-                $message .= $this->getTagInfo($tag['new']) ."\n";
+                $message .= $this->getTagInfo($newrev) ."\n";
             }
         }
-        if ($tag['changetype'] != self::TYPE_CREATED) {
-            $message .= "Old tag sha: \n" . $tag['old'];
+        if ($changetype != self::TYPE_CREATED) {
+            $message .= "Old tag sha: \n" . $oldrev;
         }
 
         $this->mail($this->emailPrefix . '[push] ' . $title , $message);
@@ -246,26 +252,121 @@ class PostReceiveHook extends ReceiveHook
     }
 
 
+
+    private function getCommitInfo($revision)
+    {
+        $raw = $this->gitExecute('rev-list -n 1 
--format="%%P%%n%%an%%n%%ae%%n%%aD%%n%%cn%%n%%ce%%n%%cD%%n%%B" %s', $revision);
+        $raw = explode("\n", $raw, 9); //8 elements separated by \n, last 
element - log message, first(skipped) element - "commit sha"
+        return [
+            'parents'           => $raw[1],  // %P
+            'author'            => $raw[2],  // %an
+            'author_email'      => $raw[3],  // %ae
+            'author_date'       => $raw[4],  // %aD
+            'committer'         => $raw[5],  // %cn
+            'committer_email'   => $raw[6],  // %ce
+            'committer_date'    => $raw[7],  // %cD
+            'log'               => $raw[8]   // %B
+        ];
+    }
+
+    private function getCommitChangedPaths($revision)
+    {
+        $raw = $this->gitExecute('show --name-status --pretty="format:" %s', 
$revision);
+        $paths = [];
+        if (preg_match_all('/([ACDMRTUXB*]+)\s+([^\n\s]+)/', $raw , $matches,  
PREG_SET_ORDER)) {
+            foreach($matches as $item) {
+                $paths[$item[2]] = $item[1];
+            }
+        }
+        return $paths;
+    }
+
     /**
+     * Send mail about commit.
+     * Subject: [git] [commit] %PROJECT% %PATHS%
+     * Body:
+     * Author: %USER%                               Thu, 08 Mar 2012 12:39:48 
+0000
+     * Committer: %USER%                               Thu, 08 Mar 2012 
12:39:48 +0000
+     *
+     * Commit: http://git.php.net/?p=%PROJECT_PATH%;a=commitdiff;h=%SHA%
+     *
+     * Log:
+     * %MESSAGE%
+     *
+     * Bug: %BUG%
+     *
+     * --part1--
+     * Changed paths:
+     * %PATHS%
+     * --/part1--
+     *
+     * --part2--
+     * Diff:
+     * %DIFF%
+     * --/part2--
+     *
      * @param $revision string
      */
     private function sendCommitMail($revision)
     {
-        $title = "Commit " . $revision . " was added";
-        $message = $title . "\n\n";
 
+        $info = $this->getCommitInfo($revision);
+        $paths = $this->getCommitChangedPaths($revision);
+        $pathsString = '';
+        foreach ($paths as $path => $action)
+        {
+            $pathsString .= '  ' . $action . '  ' . $path . "\n";
+        }
+        $diff =  $this->gitExecute('diff-tree -c -p %s', $revision);
+
+        $mail = new \Mail();
+        $mail->setSubject($this->emailPrefix . '[commit] ' . 
$this->getRepositoryName() . ' ' . implode(' ', array_keys($paths)));
 
-        $info = $this->gitExecute('diff-tree --stat --pretty=fuller -c %s', 
$revision);
+        $message = '';
 
-        $message .= $info ."\n\n";
+        $message .= 'Commit: ' . $revision . "\n";
+        $message .= 'Author: ' . $info['author'] . '(' . $info['author_email'] 
. ')         ' . $info['author_date'] . "\n";
+        $message .= 'Committer: ' . $info['committer'] . '(' . 
$info['committer_email'] . ')      ' . $info['committer_date'] . "\n";
+        if ($info['parents']) $message .= 'Parents: ' . $info['parents'] . 
"\n";
 
-        $message .= "--------DIFF--------\n";
+        $message .= "\n" . "Link: http://git.php.net/?p="; . 
$this->getRepositoryName() . ".git;a=commitdiff;h=" . $revision . "\n";
+
+        $message .= "\nLog:\n" . $info['log'] . "\n";
+
+
+        if (strlen($pathsString) < 8192) {
+            $message .= "Changed paths:\n" . $pathsString . "\n";
+            if ((strlen($pathsString) + strlen($diff)) < 8192) {
+                $message .= "Diff:\n" . $diff . "\n";
+            } else {
+                $diffFile = 'diff_' . $revision . '.txt';
+                $mail->addTextFile($diffFile, $diff);
+                if ((strlen($message) + $mail->getFileLength($diffFile)) > 
262144) {
+                    $mail->dropFile($diffFile);
+                    $message .= 'Diff: <Diff exceeded maximum size>';
+                }
+            }
+        } else {
+            $pathsFile = 'paths_' . $revision . '.txt';
+            $mail->addTextFile($pathsFile, $pathsString);
+            if ((strlen($message) + $mail->getFileLength($pathsFile)) > 
262144) {
+                $mail->dropFile($pathsFile);
+                $message .= 'Changed paths: <changed paths exceeded maximum 
size>';
+            } else {
+                $diffFile = 'diff_' . $revision . '.txt';
+                $mail->addTextFile($diffFile, $diff);
+                if ((strlen($message) + $mail->getFileLength($pathsFile) + 
$mail->getFileLength($diffFile)) > 262144) {
+                    $mail->dropFile($diffFile);
+                }
+            }
+        }
 
-        $diff = $this->gitExecute('diff-tree -c -p %s', $revision);
+        $mail->setMessage($message);
 
-        $message .= $diff ."\n\n";
+        $mail->setFrom($this->pushAuthor . '@php.net', $this->pushAuthor);
+        $mail->addTo($this->mailingList);
 
-        $this->mail($this->emailPrefix . '[commit] ' . $title , $message);
+        $mail->send();
     }
 
     /**
diff --git a/lib/Mail.php b/lib/Mail.php
new file mode 100644
index 0000000..21469b9
--- /dev/null
+++ b/lib/Mail.php
@@ -0,0 +1,169 @@
+<?php
+
+class Mail
+{
+
+    private $from = ['name' => '', 'email' => ''];
+    private $to = [];
+    private $subject = '';
+    private $message = '';
+    private $files = [];
+    private $multipart = false;
+    private $boundary = '';
+
+    const CRLF = "\r\n";
+
+    /**
+     * @param $name string unique file name
+     * @param $data string
+     */
+    public function addTextFile($name , $data)
+    {
+        $this->files[trim($name)] = chunk_split(base64_encode($data), 76, 
self::CRLF);
+    }
+
+    /**
+     * @param $name string
+     * @return int
+     */
+    public function getFileLength($name)
+    {
+        $name = trim($name);
+        return isset($this->files[$name]) ? strlen($this->files[$name]) : 0;
+    }
+
+    public function dropFile($name)
+    {
+        $name = trim($name);
+        unset($this->files[$name]);
+    }
+
+    /**
+     * @param string $email
+     * @param string $name
+     */
+    public function setFrom($email, $name = '')
+    {
+        $this->from = ['email' => trim($email), 'name' => trim($name)];
+    }
+
+    /**
+     * @param string $email
+     * @param string $name
+     */
+    public function addTo($email, $name = '')
+    {
+        $this->to[] = ['email' => trim($email), 'name' => trim($name)];
+    }
+
+    /**
+     * @param $subject string
+     */
+    public function setSubject($subject)
+    {
+        $this->subject = trim($subject);
+    }
+
+    /**
+     * @param $message string
+     */
+    public function setMessage($message)
+    {
+        $this->message = $message;
+    }
+
+
+    /**
+     * @param $name string
+     * @param $value string
+     * @return string
+     */
+    private function makeHeader($name, $value)
+    {
+        return $name . ': ' . $value;
+    }
+
+    /**
+     * @param array $address
+     * @return string
+     */
+    private function makeAddress(array $address)
+    {
+        return $address['name'] ? $this->utf8SafeEncode($address['name'], 100) 
. ' <'. $address['email']  . '>' : $address['email'];
+    }
+
+    /**
+     * @param $value string
+     * @param int $maxLenght
+     * @return string
+     */
+    private function utf8SafeEncode($value, $maxLenght = null)
+    {
+        if ($maxLenght) $value = mb_substr($value, 0, $maxLenght);
+        return mb_encode_mimeheader($value, 'UTF-8', 'Q');;
+    }
+
+    /**
+     * @return string
+     */
+    private function makeHeaders()
+    {
+        $headers = [];
+        $headers[] = $this->makeHeader('From', 
$this->makeAddress($this->from));
+        $uniq =  'php-mail-' . md5(microtime()) . mt_rand();
+        $headers[] = $this->makeHeader('Message-ID', '<' . $uniq . 
'@git.php.net>');
+        $headers[] = $this->makeHeader('MIME-Version', '1.0');
+        $headers[] = $this->makeHeader('Date', date(DATE_RFC2822, time()));
+        if ($this->multipart) {
+            $this->boundary = sha1($uniq);
+            $headers[] = $this->makeHeader('Content-Type', 'multipart/mixed; 
boundary="' . $this->boundary . '"');
+        } else {
+            $headers[] = $this->makeHeader('Content-Type', 'text/plain; 
charset="utf-8"');
+            // we use base64 for avoiding some problems sush string length 
limit, safety encoding etc.
+            $headers[] = $this->makeHeader('Content-Transfer-Encoding', 
'quoted-printable');
+        }
+        return implode(self::CRLF , $headers);
+    }
+
+    /**
+     * @return string
+     */
+    private function makeBody()
+    {
+        $body = '';
+        if ($this->multipart) {
+                $body .= '--' . $this->boundary . self::CRLF;
+                $body .= $this->makeHeader('Content-Type', 'text/plain; 
charset="utf-8"') . self::CRLF;
+                $body .= $this->makeHeader('Content-Transfer-Encoding', 
'quoted-printable') . self::CRLF;
+                $body .= self::CRLF;
+                $body .= quoted_printable_encode($this->message);
+            foreach ($this->files as $name => $data) {
+                $body .= self::CRLF . '--' . $this->boundary . self::CRLF;
+                $body .= $this->makeHeader('Content-Type', 'text/plain; 
charset="utf-8"') . self::CRLF;
+                $body .= $this->makeHeader('Content-Transfer-Encoding', 
'base64') . self::CRLF;
+                $body .= $this->makeHeader('Content-Disposition', 'attachment; 
filename="' . $name . '"') . self::CRLF;
+                $body .= self::CRLF;
+                $body .= $data;
+            }
+            $body .= self::CRLF . '--' . $this->boundary . '--';
+        } else {
+            $body = quoted_printable_encode($this->message);
+        }
+        return $body;
+    }
+
+    /**
+     * @return bool
+     */
+    public function send()
+    {
+        $this->multipart = (bool) count($this->files);
+
+        $receivers = implode(', ', array_map([$this, 'makeAddress'], 
$this->to));
+        $subject = $this->utf8SafeEncode($this->subject, 450);
+        $headers = $this->makeHeaders();
+        $body = $this->makeBody();
+
+        return mail($receivers, $subject, $body, $headers);
+    }
+}
\ No newline at end of file

commit 509b56df21c8cd0ee971c9580adadc00379df8b1
Author: Alexander Moskaliov <ir...@php.net>
Date:   Sat Mar 10 12:22:26 2012 +0400

    add mb_internal_encoding

diff --git a/hooks/post-receive b/hooks/post-receive
index 4fd4ab1..b05bd82 100755
--- a/hooks/post-receive
+++ b/hooks/post-receive
@@ -15,6 +15,7 @@ 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';
 

commit 454db4da98f95049825b3a9018542d709136a7bc
Author: Alexander Moskaliov <ir...@php.net>
Date:   Thu Mar 8 22:11:11 2012 +0400

    first part of refactoring

diff --git a/hooks/post-receive b/hooks/post-receive
index 56b583b..4fd4ab1 100755
--- a/hooks/post-receive
+++ b/hooks/post-receive
@@ -28,7 +28,7 @@ include 'Git/PostReceiveHook.php';
 
 
 $recipients = exec('git config hooks.mailinglist');
-$emailprefix = exec('git config hooks.emailprefix') ?: '[git]';
+$emailPrefix = exec('git config hooks.emailprefix') ?: '[git]';
 
 $user = null;
 if (getenv('REMOTE_USER')) {
@@ -38,5 +38,5 @@ 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, $recipients, $emailPrefix);
 $hook->process();
\ No newline at end of file
diff --git a/lib/Git/PostReceiveHook.php b/lib/Git/PostReceiveHook.php
index a5da8ef..fd8df3f 100644
--- a/lib/Git/PostReceiveHook.php
+++ b/lib/Git/PostReceiveHook.php
@@ -9,14 +9,19 @@ class PostReceiveHook extends ReceiveHook
     private $emailPrefix = '';
 
 
-    private $refs = array();
-    private $newBranches = array();
-    private $updatedBranches = array();
-    private $revisions = array();
-
-    private $allBranches = array();
-
-
+    private $refs = [];
+    private $newBranches = [];
+    private $updatedBranches = [];
+    private $revisions = [];
+
+    private $allBranches = [];
+
+    /**
+     * @param $basePath string
+     * @param $pushAuthor string
+     * @param $mailingList string
+     * @param $emailPrefix string
+     */
     public function __construct($basePath, $pushAuthor, $mailingList, 
$emailPrefix)
     {
         parent::__construct($basePath);
@@ -28,14 +33,13 @@ class PostReceiveHook extends ReceiveHook
         $this->allBranches = $this->getAllBranches();
     }
 
-    private function getAllBranches()
-    {
-        return explode("\n", $this->execute('git for-each-ref 
--format="%%(refname)" "refs/heads/*"'));
-    }
-
-
-    private function execute($cmd)
+    /**
+     * @param $cmd string
+     * @return string
+     */
+    private function gitExecute($cmd)
     {
+        $cmd = \Git::GIT_EXECUTABLE . " --git-dir=" . $this->repositoryPath . 
" " . $cmd;
         $args = func_get_args();
         array_shift($args);
         $cmd = vsprintf($cmd, $args);
@@ -43,6 +47,17 @@ class PostReceiveHook extends ReceiveHook
         return $output;
     }
 
+    /**
+     * @return array
+     */
+    private function getAllBranches()
+    {
+        return explode("\n", $this->gitExecute('for-each-ref 
--format="%%(refname)" "refs/heads/*"'));
+    }
+
+    /**
+     *
+     */
     public function process()
     {
         $this->refs = $this->hookInput();
@@ -76,6 +91,9 @@ class PostReceiveHook extends ReceiveHook
 
     }
 
+    /**
+     * @param array $branch
+     */
     private function sendBranchMail(array $branch)
     {
 
@@ -105,7 +123,7 @@ class PostReceiveHook extends ReceiveHook
                 $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']))) {
+                    if 
($this->isRevExistsInBranches($this->refs[$refname]['old'],[$branch['refname']]))
 {
                         $this->cacheRevisions($branch['refname'], 
$this->getRevisions($this->refs[$refname]['old'] . '..' . $branch['new']));
                     }
                 }
@@ -116,8 +134,8 @@ class PostReceiveHook extends ReceiveHook
             if (count($revisions)) {
                 $message .= "--------LOG--------\n";
                 foreach ($revisions as $revision) {
-                    $diff = $this->execute(
-                        'git diff-tree --stat --pretty=medium -c %s',
+                    $diff = $this->gitExecute(
+                        'diff-tree --stat --pretty=medium -c %s',
                         $revision
                     );
 
@@ -130,6 +148,10 @@ class PostReceiveHook extends ReceiveHook
     }
 
 
+    /**
+     * @param $branchName string
+     * @param array $revisions
+     */
     private function cacheRevisions($branchName, array $revisions)
     {
         //TODO: add mail order from older commit to newer
@@ -140,6 +162,9 @@ class PostReceiveHook extends ReceiveHook
     }
 
 
+    /**
+     * @param array $tag
+     */
     private function sendTagMail(array $tag)
     {
 
@@ -169,75 +194,100 @@ class PostReceiveHook extends ReceiveHook
         $this->mail($this->emailPrefix . '[push] ' . $title , $message);
     }
 
+    /**
+     * @param $tag string
+     * @return string
+     */
     private function getTagInfo($tag)
     {
         $info = "Target:\n";
-        $info .= $this->execute('git diff-tree --stat --pretty=medium -c %s', 
$tag);
+        $info .= $this->gitExecute('diff-tree --stat --pretty=medium -c %s', 
$tag);
         return $info;
     }
 
+    /**
+     * @param $tag string
+     * @return string
+     */
     private function getAnnotatedTagInfo($tag)
     {
-        $tagInfo = $this->execute('git for-each-ref --format="%%(*objectname) 
%%(taggername) %%(taggerdate)" %s', $tag);
+        $tagInfo = $this->gitExecute('for-each-ref --format="%%(*objectname) 
%%(taggername) %%(taggerdate)" %s', $tag);
         list($target, $tagger, $taggerdate) = explode(' ', $tagInfo);
 
         $info = "Tagger: " . $tagger . "\n";
         $info .= "Date: " . $taggerdate . "\n";
-        $info .= $this->execute("git cat-file tag %s | sed -e '1,/^$/d'", 
$tag)."\n";
+        $info .= $this->gitExecute("cat-file tag %s | sed -e '1,/^$/d'", 
$tag)."\n";
         $info .= "Target:\n";
-        $info .= $this->execute('git diff-tree --stat --pretty=medium -c %s', 
$target);
+        $info .= $this->gitExecute('diff-tree --stat --pretty=medium -c %s', 
$target);
         return $info;
     }
 
+    /**
+     * @param $rev string
+     * @return bool
+     */
     private function isAnnotatedTag($rev)
     {
-        return trim($this->execute('git for-each-ref --format="%%(objecttype)" 
%s', $rev)) == 'tag';
+        return trim($this->gitExecute('for-each-ref --format="%%(objecttype)" 
%s', $rev)) == 'tag';
     }
 
-
+    /**
+     * @param $revRange string
+     * @return array
+     */
     private function getRevisions($revRange)
     {
-        $output = $this->execute(
-            'git rev-list %s',
+        $output = $this->gitExecute(
+            'rev-list %s',
             $revRange
         );
-        $revisions = $output ? explode("\n", trim($output)) : array();
+        $revisions = $output ? explode("\n", trim($output)) : [];
         return $revisions;
     }
 
 
+    /**
+     * @param $revision string
+     */
     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);
+        $info = $this->gitExecute('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);
+        $diff = $this->gitExecute('diff-tree -c -p %s', $revision);
 
         $message .= $diff ."\n\n";
 
         $this->mail($this->emailPrefix . '[commit] ' . $title , $message);
     }
 
-
+    /**
+     * @param $subject string
+     * @param $message string
+     */
     private function mail($subject, $message) {
-        $headers = array(
+        $headers = [
             'From: ' . $this->pushAuthor . '@php.net',
             'Reply-To: ' . $this->pushAuthor . '@php.net'
-        );
+        ];
 
         mail($this->mailingList, $subject, $message, implode("\r\n", 
$headers));
     }
 
-
+    /**
+     * @param $revision string
+     * @param array $branches
+     * @return bool
+     */
     private function isRevExistsInBranches($revision, array $branches) {
-        return !(bool) $this->execute('git rev-list --max-count=1 %s --not 
%s', $revision, implode(' ', $branches));
+        return !(bool) $this->gitExecute('rev-list --max-count=1 %s --not %s', 
$revision, implode(' ', $branches));
     }
 
 }
diff --git a/lib/Git/ReceiveHook.php b/lib/Git/ReceiveHook.php
index f957fc7..420cfe9 100644
--- a/lib/Git/ReceiveHook.php
+++ b/lib/Git/ReceiveHook.php
@@ -13,10 +13,12 @@ abstract class ReceiveHook
     const REF_TAG = 1;
 
     private $repositoryName = '';
+    protected $repositoryPath = '';
 
     public function __construct($basePath)
     {
-        $rel_path = str_replace($basePath, '', \Git::getRepositoryPath());
+        $this->repositoryPath = \Git::getRepositoryPath();
+        $rel_path = str_replace($basePath, '', $this->repositoryPath);
         if (preg_match('@/(.*\.git)$@', $rel_path, $matches)) {
             $this->repositoryName = $matches[1];
         }
@@ -48,16 +50,16 @@ abstract class ReceiveHook
      */
     public function hookInput()
     {
-        $parsed_input = array();
+        $parsed_input = [];
         while (!feof(STDIN)) {
             $line = fgets(STDIN);
             if (preg_match(self::INPUT_PATTERN, $line, $matches)) {
 
-                $ref = array(
+                $ref = [
                     'old'     => $matches[1],
                     'new'     => $matches[2],
                     'refname' => $matches[3]
-                );
+                ];
 
                 if (preg_match('~^refs/heads/.+$~', $ref['refname'])) {
                     // git push origin branchname

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