Commit: e6da86fbb22bc773980c2ecde77bb8875641a097
Author: Florian Anderiasch(f...@php.net)         Thu, 8 Mar 2012 08:49:25 +0100
Committer: Florian Anderiasch(f...@php.net)      Thu, 8 Mar 2012 08:49:25 +0100
Parents: 275c3770c3bc0ce710328cd2b35989f18e02ecc9 
fc9c78fe12aa756060684e565adf8fb8a4373120

Link: 
http://git.php.net/?p=karma.git;a=commitdiff;h=e6da86fbb22bc773980c2ecde77bb8875641a097

Log:
Merge branch 'master' of https://git.php.net/repository/karma

Changed paths:
  MM  lib/Git/ReceiveHook.php


Diff:
e6da86fbb22bc773980c2ecde77bb8875641a097
diff --combined lib/Git/ReceiveHook.php
index 8faadcd,b51a5f4..f90df10
--- a/lib/Git/ReceiveHook.php
+++ b/lib/Git/ReceiveHook.php
@@@ -3,7 -3,6 +3,6 @@@ namespace Git
  
  class ReceiveHook
  {
-     const GIT_EXECUTABLE = 'git';
      const INPUT_PATTERN = '@^([0-9a-f]{40}) ([0-9a-f]{40}) (.+)$@i';
  
      private $karmaFile;
@@@ -22,7 -21,7 +21,7 @@@
       */
      public function isKarmaIgnored()
      {
-         return 'true' === exec(sprintf('%s config karma.ignored', 
self::GIT_EXECUTABLE));
+         return 'true' === exec(sprintf('%s config karma.ignored', 
\Git::GIT_EXECUTABLE));
      }
  
      /**
@@@ -35,7 -34,7 +34,7 @@@
       */
      public function getRepositoryName()
      {
-         $rel_path = str_replace($this->repositoryBasePath, '', 
$this->getRepositoryPath());
+         $rel_path = str_replace($this->repositoryBasePath, '', 
\Git::getRepositoryPath());
          if (preg_match('@/(.*\.git)$@', $rel_path, $matches)) {
              return $matches[1];
          }
@@@ -43,22 -42,13 +42,13 @@@
          return '';
      }
  
-     /**
-      * Returns the path to the current repository.
-      *
-      * Tries to determine the path of the current repository in which
-      * the hook was invoked.
-      *
-      * @return string
-      */
-     public function getRepositoryPath()
-     {
-         $path = exec(sprintf('%s rev-parse --git-dir', self::GIT_EXECUTABLE));
-         if (!is_dir($path)) {
-             return false;
+     public function mapInput(callable $fn) {
+         $result = [];
+         foreach($this->hookInput() as $input) {
+             $result[] = $fn($input['old'], $input['new']);
          }
  
-         return realpath($path);
+         return $result;
      }
  
      /**
@@@ -109,77 -99,36 +99,82 @@@
       */
      private function getReceivedPathsForRange($old, $new)
      {
-         $repourl = $this->getRepositoryPath();
+         $repourl = \Git::getRepositoryPath();
          $output  = [];
  
          /* there is the case where we push a new branch. check only new 
commits.
             in case its a brand new repo, no heads will be available. */
-         if ($old == '0000000000000000000000000000000000000000') {
+         if ($old == \Git::NULLREV) {
              exec(
                  sprintf("%s --git-dir=%s for-each-ref --format='%%(refname)' 
'refs/heads/*'",
-                     self::GIT_EXECUTABLE, $repourl), $output);
+                     \Git::GIT_EXECUTABLE, $repourl), $output);
              /* do we have heads? otherwise it's a new repo! */
-             $heads = implode(' ', $output);
-             $not   = count($output) > 0 ? sprintf('--not %s', 
escapeshellarg($heads)) : '';
+             if (count($output) > 0) {
+                 $not = array_map(
+                     function($x) {
+                         return sprintf('--not %s', escapeshellarg($x));
+                     }, $output);
+                 $not = implode(' ', $not);
+             }
              exec(
                  sprintf('%s --git-dir=%s log --name-only --pretty=format:"" 
%s %s',
-                 self::GIT_EXECUTABLE, $repourl, $not,
+                 \Git::GIT_EXECUTABLE, $repourl, $not,
                  escapeshellarg($new)), $output);
          } else {
              exec(
                  sprintf('%s --git-dir=%s log --name-only --pretty=format:"" 
%s..%s',
-                 self::GIT_EXECUTABLE, $repourl, escapeshellarg($old),
+                 \Git::GIT_EXECUTABLE, $repourl, escapeshellarg($old),
                  escapeshellarg($new)), $output);
          }
          return $output;
      }
  
 +    /**
 +     * 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 = $this->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',
 +                self::GIT_EXECUTABLE,
 +                $repourl,
 +                $not,
 +                escapeshellarg($new)
 +            );
 +            exec($cmd, $output);
 +        } else {
 +            $cmd = sprintf(
 +                '%s --git-dir=%s log --pretty=format:"[%%ae] %%H %%s" %s..%s',
 +                self::GIT_EXECUTABLE,
 +                $repourl,
 +                escapeshellarg($old),
 +                escapeshellarg($new)
 +            );
 +            exec($cmd, $output);
 +        }
 +
 +        return $output;
 +    }
 +
      public function getReceivedPaths()
      {
          $parsed_input = $this->hookInput();
@@@ -196,21 -145,4 +191,21 @@@
  
          return array_unique($paths);
      }
 +
 +    public function getReceivedMessages()
 +    {
 +        $parsed_input = $this->hookInput();
 +
 +        $paths = array_map(
 +            function ($input) {
 +                return $this->getReceivedMessagesForRange($input['old'], 
$input['new']);
 +            },
 +            $parsed_input);
 +
 +        /* remove empty lines, and flattern the array */
 +        $flattend = array_reduce($paths, 'array_merge', []);
 +        $paths    = array_filter($flattend);
 +
 +        return array_unique($paths);
 +    }
  }



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

Reply via email to