[git][commit] karma.git: lib/Git/ReceiveHook.php
| From: | David Soria Parra | Date: | Sun, 18 Mar 2012 20:11:11 +0000 |
| Subject: | [git][commit] karma.git: lib/Git/ReceiveHook.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-67940@lists.php.net to get a copy of this message | ||
Commit: 2f637ccbfef5fcd60b2e905ea486b60100c020e2
Author: Florian Anderiasch(fa@php.net) Thu, 8 Mar 2012 07:14:08 +0100
Committer: Florian Anderiasch(fa@php.net) Thu, 8 Mar 2012 07:14:08 +0100
Parents: 8d595325d65b7de86651483a1705a0ee2a4b4bd5
Link: http://git.php.net/?p=karma.git;a=commitdiff;h=2f637ccbfef5fcd60b2e905ea486b60100c020e2
Log:
Add methods to extract commit messages
Changed paths:
M lib/Git/ReceiveHook.php
Diff:
2f637ccbfef5fcd60b2e905ea486b60100c020e2
diff --git a/lib/Git/ReceiveHook.php b/lib/Git/ReceiveHook.php
index 6776a2a..8faadcd 100644
--- a/lib/Git/ReceiveHook.php
+++ b/lib/Git/ReceiveHook.php
@@ -134,6 +134,52 @@ class ReceiveHook
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();
@@ -150,4 +196,21 @@ class ReceiveHook
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);
+ }
}