3 * concept is to merge commits from a live or working tree
4 * into the 'release tree'
7 * step 1 = render the log of differences..
11 * -- our doc commit changes loads of files.. and makes the layout pointless.
12 * -- ?? grouping by day??? // expand/collapse..
17 require_once 'Pman.php';
19 class Pman_MTrack_Merger extends Pman {
22 var $release = 'github';
25 // function getAuth() - from log..
29 $au = $this->getAuthUser();
30 if (!$au || $au->company()->comptype != 'OWNER') {
33 $this->authUser = $au;
41 $this->pi = 'default/roojs1'; // fixme..
43 $this->repo = DB_DataObject::factory('mtrack_repos');
44 $this->filename = $this->repo->loadFromPath($this->pi);
46 if (!$this->repo->id) {
47 $this->err("invalid repo");
50 //if (!$this->projectPerm($this->repo->project_id, 'MTrack.Repos', 'S')) {
51 // $this->err("no perm for this repo ");
53 if (isset($_REQUEST['_tree'])) {
57 if (isset($_REQUEST['_changedFiles'])) {
58 $this->changedFiles($_REQUEST['_changedFiles']);
60 $this->jerr("invalid url");
73 $this->repo->debug = 1;
74 $ar = $this->repo->history("/", null, "rev", "{$this->release}..{$this->live}");
76 // the point of this is to extract all the revisions, and group them.
80 //echo '<PRE>';print_R($ar);
82 // need to get a 2 dimensional array of
83 // files along top, and commints down.
86 foreach($ar as $commit) {
88 $files = $commit->files;
89 $day = date("Y-m-d", strtotime($commit->ctime));
90 if (!isset($days[$day])) {
97 $time= date("H:i:s", strtotime($commit->ctime));
98 if (!isset($days[$day]['children'][$time])) {
99 $days[$day]['children'][$time] = array(
101 'rev' => $day . ' ' . $time,
105 $days[$day]['children'][$time]['children'][] = array(
106 'text'=> $commit->changelog,
107 'rev' => $commit->rev,
113 foreach($days as $d=>$do) {
114 $dcn = $do['children'];
115 $do['children'] = array();
116 foreach($dcn as $t=>$to) {
117 $to['rev'] = $to['children'][0]['rev'];
118 $do['children'][] = $to;
120 $do['rev'] = $do['children'][0]['rev'];
134 function changedFiles($rev)
136 // list the files that have changed..
137 // in theory you could click a number of them and only merge those changes..
138 // need to do a git diff.. and just get a list of files..
140 $rev = preg_replace('/[^a-z0-9]+/', '',$rev);
141 $this->repo->impl()->debug = 1;
142 $fh = $this->repo->impl()->git('diff', '--numstat' , "{$this->release}..{$rev}", '--', "");
143 // returns ADDED \t REMOVED \t NAME (might include rename/etc. info)
146 while (false !== ($line = fread($fh, 4096))) {
147 $ar = explode("\t", trim($line));
151 'filename' => $ar[2],