[git] commit karma.git: hooks/post-receive.bugsweb lib/Git/BugsWebPostReceiveHook.php
| From: | David Soria Parra | Date: | Mon, 19 Mar 2012 15:28:38 +0000 |
| Subject: | [git] commit karma.git: hooks/post-receive.bugsweb lib/Git/BugsWebPostReceiveHook.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-67952@lists.php.net to get a copy of this message | ||
Commit: efd58e9da03931adc336fbf3400a94d4103f5fbf
Author: Florian Anderiasch(fa@php.net) Mon, 19 Mar 2012 16:03:36 +0100
Committer: Florian Anderiasch(fa@php.net) Mon, 19 Mar 2012 16:03:36 +0100
Parents: db438a4a9ec117fec2767de6a0f79147d48285cc
Link: http://git.php.net/?p=karma.git;a=commitdiff;h=efd58e9da03931adc336fbf3400a94d4103f5fbf
Log:
Update to changed ReceiveHook
Changed paths:
M hooks/post-receive.bugsweb
A lib/Git/BugsWebPostReceiveHook.php
Diff:
efd58e9da03931adc336fbf3400a94d4103f5fbf
diff --git a/hooks/post-receive.bugsweb b/hooks/post-receive.bugsweb
index 9ab2bc3..1c53f0d 100755
--- a/hooks/post-receive.bugsweb
+++ b/hooks/post-receive.bugsweb
@@ -16,6 +16,7 @@ include 'Git.php';
include 'Git/PushInformation.php';
include 'Git/ReceiveHook.php';
include 'Git/PostReceiveHook.php';
+include 'Git/BugsWebPostReceiveHook.php';
$recipients = exec('git config hooks..mailinglist');
$emailPrefix = exec('git config hooks.emailprefix') ?: '[git]';
@@ -28,7 +29,7 @@ if (getenv('REMOTE_USER')) {
$user = getenv('GL_USER');
}
-$hook = new \Git\PostReceiveHook(KARMA_FILE, REPOSITORY_PATH);
+$hook = new \Git\BugsWebPostReceiveHook(KARMA_FILE, REPOSITORY_PATH);
$rpath = $hook->getReceivedMessages(
getenv('GL_REPO_BASE_ABS') ?: REPOSITORY_PATH,
$user,
diff --git a/lib/Git/BugsWebPostReceiveHook.php b/lib/Git/BugsWebPostReceiveHook.php
new file mode 100644
index 0000000..13e263b
--- /dev/null
+++ b/lib/Git/BugsWebPostReceiveHook.php
@@ -0,0 +1,69 @@
+<?php
+namespace Git;
+
+class BugsWebPostReceiveHook extends ReceiveHook
+{
+
+ public function getReceivedMessages()
+ {
+ $this->hookInput();
+
+ $paths = array_map(
+ function ($input) {
+ return $this->getReceivedMessagesForRange($input['old'],
$input['new']);
+ },
+ $this->refs);
+
+ /* remove empty lines, and flattern the array */
+ $flattend = array_reduce($paths, 'array_merge', []);
+ $paths = array_filter($flattend);
+
+ return array_unique($paths);
+ }
+
+ /**
+ * 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 = \Git::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',
+ \Git::GIT_EXECUTABLE,
+ $repourl,
+ $not,
+ escapeshellarg($new)
+ );
+ exec($cmd, $output);
+ } else {
+ $cmd = sprintf(
+ '%s --git-dir=%s log --pretty=format:"[%%ae] %%H %%s" %s..%s',
+ \Git::GIT_EXECUTABLE,
+ $repourl,
+ escapeshellarg($old),
+ escapeshellarg($new)
+ );
+ exec($cmd, $output);
+ }
+
+ return $output;
+ }
+}
\ No newline at end of file