final move of files
[web.mtrack] / MTrack / SCM / Svn / CommitHookBridge.php
1 <?php 
2
3
4 class MTrack_SCM_Svn_CommitHookBridge extends  IMTrackCommitHookBridge 
5 {
6     var $repo;
7     var $svnlook;
8     var $svnrepo;
9     var $svntxn;
10
11     function __construct($repo, $svnrepo, $svntxn) 
12     {
13         $this->repo = $repo;
14         $this->svnlook = MTrackConfig::get('tools', 'svnlook');
15         $this->svnrepo = $svnrepo;
16         $this->svntxn = explode(' ', $svntxn,2);
17     }
18
19     function enumChangedOrModifiedFileNames() 
20     {
21         $files = array();
22         $fp = $this->run($this->svnlook, 'changed', $this->svntxn, $this->svnrepo);
23         while (($line = fgets($fp)) !== false) {
24           if (preg_match("/^(\w)\s+(.*)$/", trim($line), $M)) {
25             $action = $M[1];
26             $path = $M[2];
27             if ($action == 'A' || $action == 'U' || $action == 'UU') {
28               $files[] = $path;
29             }
30           }
31         }
32         return $files;
33     }
34
35     function getCommitMessage()
36     {
37         $fp = $this->run($this->svnlook, 'log', $this->svntxn, $this->svnrepo);
38         
39         $log = stream_get_contents($fp);
40         $log = preg_replace('/\[(\d+)\]/',
41           "[changeset:" . $this->repo->getBrowseRootName() . ",\$1]", $log);
42         return $log;
43     }
44     
45     function getDiffStream($path)
46     {
47         return  $this->run($this->svnlook, 'diff', $this->svntxn, $this->svnrepo, $path);
48     }
49     
50     function getFileStream($path) 
51     {
52         return  $this->run($this->svnlook, 'cat', $this->svntxn, $this->svnrepo, $path);
53     }
54
55     function getChangesetDescriptor()
56     {
57         $rev = $this->svntxn[1];
58         return '[changeset:' . $this->repo->getBrowseRootName() . ",$rev]";
59     }
60 }