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 'MTrackWeb/Log.php';
18
19 class Pman_MTrack_Merger extends Pman {
20     
21     
22     // function getAuth() - from log..
23     function getAuth()
24     {
25         parent::getAuth();
26         $au = $this->getAuthUser();
27         if (!$au || $au->company()->comptype != 'OWNER') {
28             $this->jautherr();
29         }
30         $this->authUser = $au;
31         return true;
32     }
33     
34     
35     function get($pi)
36     {
37         
38         $this->pi = 'default/roojs1'; // fixme..
39         
40         $this->repo = DB_DataObject::factory('mtrack_repos');
41         $this->filename = $this->repo->loadFromPath($this->pi);
42         
43         if (!$this->repo->id) {
44             $this->err("invalid repo");
45         };
46           
47         //if (!$this->projectPerm($this->repo->project_id, 'MTrack.Repos', 'S')) {
48         //    $this->err("no perm for this repo ");
49         //}
50           
51         $this->tree();
52         
53         
54         exit;
55         
56     }
57     function tree()
58     {
59         
60         $live = 'master';
61         $release = 'github';
62          
63         $this->repo->debug = 1;
64         $ar = $this->repo->history("/", null, "rev",  "$release..$live");
65         
66         // the point of this is to extract all the revisions, and group them.
67         
68         
69         
70         //echo '<PRE>';print_R($ar);
71         
72         // need to get a 2 dimensional array of
73         // files along top, and commints down.
74         $cfiles = array();
75         $rows = array();
76         foreach($ar as $commit) {
77             
78             $files = $commit->files;
79             $day = date("Y-m-d", strtotime($commit->ctime));
80             if (!isset($days[$day])) { 
81                 $days[$day] = array(
82                     'text' => $day,
83                     'rev' => $day,
84                     'children' => array()
85                 );
86             }
87             $time= date("H:i:s", strtotime($commit->ctime));
88             if (!isset($days[$day]['children'][$time])) { 
89                 $days[$day]['children'][$time] = array(
90                     'text' => $time,
91                     'rev' => $day . ' ' . $time,
92                     'commits' =>array(),
93                 );
94             }
95             $days[$day]['children'][$time]['children'][] = array(
96                 'title'=> $commit->changelog,
97                 'rev' => $commit->rev
98             );
99         }
100         $out = array();
101         foreach($days as $d=>$do) {
102             
103             $cn = $do['children'];
104             $do['children'] = array();
105             foreach($do['children'] as $c=>$co) {
106                 $do['children'] = $co;
107             }
108             $out[] = $dd
109         }
110         
111         
112         // convert our into a tree..
113         
114         // this might result in alot of white boxes where you can
115         // let's see what it looks like..
116         echo '<PRE>';print_R($days);
117         
118         
119         
120         
121         
122     }
123     
124     
125 }