From 2ad13a96f923db98caf97d7afeeca066a42a8cf6 Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Thu, 15 Apr 2010 15:20:50 +0200 Subject: [PATCH] Added the changegroup hook for Mercurial. This is the last commit for 1.0, yeah\! --- doc/syncmercurial.mdtext | 5 +++ scripts/hgchangegroup.php | 61 ++++++++++++++++++++++++++++++++ src/IDF/Plugin/SyncMercurial.php | 26 ++++++++++++++ 3 files changed, 92 insertions(+) create mode 100755 scripts/hgchangegroup.php diff --git a/doc/syncmercurial.mdtext b/doc/syncmercurial.mdtext index 30149bd..d8b3094 100644 --- a/doc/syncmercurial.mdtext +++ b/doc/syncmercurial.mdtext @@ -84,3 +84,8 @@ Each time this file is modified, a temporary file is created. */5 * * * * /bin/sh /home/indefero/src/scripts/SyncMercurial.sh Edit this script and add correct values to `private_notify` and `reload_cmd`. + +## Hook configuratin + + [hooks] + changegroup = /home/indefero/src/scripts/hgchangegroup.php diff --git a/scripts/hgchangegroup.php b/scripts/hgchangegroup.php new file mode 100755 index 0000000..b1358ee --- /dev/null +++ b/scripts/hgchangegroup.php @@ -0,0 +1,61 @@ +#!/usr/bin/env php + '/relative/path/to/hg/repository', + * 'env' => array_merge($_ENV, $_SERVER)); + * + */ +$params = array('rel_dir' => $_ENV['PATH_INFO'], + 'env' => array_merge($_ENV, $_SERVER)); +Pluf_Signal::send('hgchangegroup.php::run', 'hgchangegroup.php', $params); + + diff --git a/src/IDF/Plugin/SyncMercurial.php b/src/IDF/Plugin/SyncMercurial.php index 37a6c48..db2acf4 100644 --- a/src/IDF/Plugin/SyncMercurial.php +++ b/src/IDF/Plugin/SyncMercurial.php @@ -51,6 +51,9 @@ class IDF_Plugin_SyncMercurial case 'Pluf_User::passwordUpdated': $plug->processSyncPasswd($params['user']); break; + case 'hgchangegroup.php::run': + $plug->processSyncTimeline($params); + break; } } @@ -222,4 +225,27 @@ class IDF_Plugin_SyncMercurial file_put_contents($notify_file, ' ', LOCK_EX); return true; } + + /** + * Update the timeline in post commit. + * + */ + public function processSyncTimeline($params) + { + $repo_dir = $params['rel_dir']; + $elts = preg_split('#/#', $repo_dir, -1, PREG_SPLIT_NO_EMPTY); + $pname = array_pop($elts); + try { + $project = IDF_Project::getOr404($pname); + } catch (Pluf_HTTP_Error404 $e) { + Pluf_Log::event(array('IDF_Plugin_SyncMercurial::processSyncTimeline', 'Project not found.', array($pname, $params))); + return false; // Project not found + } + // Now we have the project and can update the timeline + Pluf_Log::debug(array('IDF_Plugin_SyncMercurial::processSyncTimeline', 'Project found', $pname, $project->id)); + IDF_Scm::syncTimeline($project, true); + Pluf_Log::event(array('IDF_Plugin_SyncMercurial::processSyncTimeline', 'sync', array($pname, $project->id))); + + + } }