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     
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                 'text'=> $commit->changelog,
97                 'rev' => $commit->rev,
98                 'leaf' => true
99             );
100         }
101         $out = array();
102         
103         foreach($days as $d=>$do) {
104             $dcn = $do['children'];
105             $do['children'] = array();
106             foreach($dcn as $t=>$to) {
107                 $to['rev']  = $to['children'][0]['rev'];
108                 $do['children'][] = $to;
109             }
110             $do['rev'] = $do['children'][0]['rev'];
111             $out[] = $do;
112         }
113         
114         $this->jdata($out);
115         
116          
117         
118     }
119     
120     
121
122
123
124     function changedFiles()
125     {
126         // list the files that have changed..
127         // in theory you could click a number of them and only merge those changes..
128         
129     }
130 }