2 <?php # vim:ts=2:sw=2:et:ft=php:
3 /* For licensing and copyright terms, see the file named LICENSE */
5 // svn-commit-hook what svnrepopath svntxn [mtrackconfig]
11 if (isset($argv[4])) {
12 putenv("MTRACK_CONFIG_FILE=" . $argv[4]);
15 if ($action == 'pre') {
16 $svntxn = "-t $svntxn";
18 $svntxn = "-r $svntxn";
21 include dirname(__FILE__) . '/../inc/common.php';
22 if (file_exists(MTrackConfig::get('core', 'vardir') . '/.initializing')) {
27 class SvnCommitHookBridge implements IMTrackCommitHookBridge {
33 function __construct($repo, $svnrepo, $svntxn) {
35 $this->svnlook = MTrackConfig::get('tools', 'svnlook');
36 $this->svnrepo = $svnrepo;
37 $this->svntxn = $svntxn;
40 function enumChangedOrModifiedFileNames() {
42 $fp = popen("$this->svnlook changed $this->svntxn $this->svnrepo", 'r');
43 while (($line = fgets($fp)) !== false) {
44 if (preg_match("/^(\w)\s+(.*)$/", trim($line), $M)) {
47 if ($action == 'A' || $action == 'U' || $action == 'UU') {
55 function getCommitMessage() {
56 $fp = popen("$this->svnlook log $this->svntxn $this->svnrepo", 'r');
57 $log = stream_get_contents($fp);
58 $log = preg_replace('/\[(\d+)\]/',
59 "[changeset:" . $this->repo->getBrowseRootName() . ",\$1]", $log);
63 function getFileStream($path) {
65 "$this->svnlook cat $this->svntxn $this->svnrepo $path", 'r');
68 function getChangesetDescriptor() {
69 $rev = trim(str_replace('-r ', '', $this->svntxn));
70 return '[changeset:' . $this->repo->getBrowseRootName() . ",$rev]";
75 $repo = MTrackRepo::loadByLocation($svnrepo);
76 $bridge = new SvnCommitHookBridge($repo, $svnrepo, $svntxn);
77 $author = trim(shell_exec("$bridge->svnlook author $svntxn $svnrepo"));
78 $author = mtrack_canon_username($author);
79 MTrackAuth::su($author);
80 $checker = new MTrackCommitChecker($repo);
81 if ($action == 'pre') {
82 $checker->preCommit($bridge);
84 $checker->postCommit($bridge);
87 } catch (Exception $e) {
88 fwrite(STDERR, "\n" . $e->getMessage() . "\n\n ** Commit failed [$action]\n");