Merger.php
[Pman.MTrack] / Merger.php
1 <?php
2 /**
3  * concept is to merge commits from a live or working tree
4  * into the 'release tree'
5  *
6  *
7  * step 1 = render the log of differences..
8  *
9  *
10  * First run issues:
11  *  -- our doc commit changes loads of files.. and makes the layout pointless.
12  *  -- ?? grouping by day??? // expand/collapse.. 
13  * 
14  *
15  */
16
17 require_once 'Pman.php';
18
19 class Pman_MTrack_Merger extends Pman {
20     
21     $this->live = 'master';
22     $this->release = 'github';
23     // function getAuth() - from log..
24     function getAuth()
25     {
26         parent::getAuth();
27         $au = $this->getAuthUser();
28         if (!$au || $au->company()->comptype != 'OWNER') {
29             $this->jautherr();
30         }
31         $this->authUser = $au;
32         return true;
33     }
34     
35     
36     function get($pi)
37     {
38         
39         $this->pi = 'default/roojs1'; // fixme..
40         
41         $this->repo = DB_DataObject::factory('mtrack_repos');
42         $this->filename = $this->repo->loadFromPath($this->pi);
43         
44         if (!$this->repo->id) {
45             $this->err("invalid repo");
46         };
47           
48         //if (!$this->projectPerm($this->repo->project_id, 'MTrack.Repos', 'S')) {
49         //    $this->err("no perm for this repo ");
50         //}
51         if (isset($_REQUEST['_tree'])) {
52             $this->tree();
53         }
54         
55         if (isset($_REQUEST['_changedFiles'])) {
56             $this->changedFiles($_REQUEST['_changedFiles']);
57         }
58         $this->jerr("invalid url");
59         exit;
60         
61     }
62     
63     
64     
65     function tree()
66     {
67         
68         $live = 'master';
69         $release = 'github';
70          
71         $this->repo->debug = 1;
72         $ar = $this->repo->history("/", null, "rev",  "{$this->release}..{$this->live}");
73         
74         // the point of this is to extract all the revisions, and group them.
75         
76         
77         
78         //echo '<PRE>';print_R($ar);
79         
80         // need to get a 2 dimensional array of
81         // files along top, and commints down.
82         $cfiles = array();
83         $rows = array();
84         foreach($ar as $commit) {
85             
86             $files = $commit->files;
87             $day = date("Y-m-d", strtotime($commit->ctime));
88             if (!isset($days[$day])) { 
89                 $days[$day] = array(
90                     'text' => $day,
91                     'rev' => $day,
92                     'children' => array()
93                 );
94             }
95             $time= date("H:i:s", strtotime($commit->ctime));
96             if (!isset($days[$day]['children'][$time])) { 
97                 $days[$day]['children'][$time] = array(
98                     'text' => $time,
99                     'rev' => $day . ' ' . $time,
100                     'commits' =>array(),
101                 );
102             }
103             $days[$day]['children'][$time]['children'][] = array(
104                 'text'=> $commit->changelog,
105                 'rev' => $commit->rev,
106                 'leaf' => true
107             );
108         }
109         $out = array();
110         
111         foreach($days as $d=>$do) {
112             $dcn = $do['children'];
113             $do['children'] = array();
114             foreach($dcn as $t=>$to) {
115                 $to['rev']  = $to['children'][0]['rev'];
116                 $do['children'][] = $to;
117             }
118             $do['rev'] = $do['children'][0]['rev'];
119             $out[] = $do;
120         }
121         
122         $this->jdata($out);
123         
124          
125         
126     }
127     
128     
129
130
131
132     function changedFiles($rev)
133     {
134         // list the files that have changed..
135         // in theory you could click a number of them and only merge those changes..
136         // need to do a git diff.. and just get a list of files..
137         
138         $rev = preg_replace('/[^a-z0-9]+/', '');
139         $fh = $this->repo->git('diff', "{$this->release}..{$rev}", '--', "");
140         
141         echo stream_get_contents($fh);
142      
143
144     }
145 }