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 if (isset($_REQUEST['_preview'])) {
61 $this->preview($_REQUEST['_preview']);
64 $this->jerr("invalid url");
70 return $this->get($pi);
79 $this->repo->debug = 1;
80 $ar = $this->repo->history("/", null, "rev", "{$this->release}..{$this->live}");
82 // the point of this is to extract all the revisions, and group them.
86 //echo '<PRE>';print_R($ar);
88 // need to get a 2 dimensional array of
89 // files along top, and commints down.
92 foreach($ar as $commit) {
94 $files = $commit->files;
95 $day = date("Y-m-d", strtotime($commit->ctime));
96 if (!isset($days[$day])) {
100 'children' => array()
103 $time= date("H:i:s", strtotime($commit->ctime));
104 if (!isset($days[$day]['children'][$time])) {
105 $days[$day]['children'][$time] = array(
107 'rev' => $day . ' ' . $time,
111 $days[$day]['children'][$time]['children'][] = array(
112 'text'=> $commit->changelog,
113 'rev' => $commit->rev,
119 foreach($days as $d=>$do) {
120 $dcn = $do['children'];
121 $do['children'] = array();
122 foreach($dcn as $t=>$to) {
123 $to['rev'] = $to['children'][0]['rev'];
124 $do['children'][] = $to;
126 $do['rev'] = $do['children'][0]['rev'];
140 function changedFiles($rev)
142 // list the files that have changed..
143 // in theory you could click a number of them and only merge those changes..
144 // need to do a git diff.. and just get a list of files..
146 $rev = preg_replace('/[^a-z0-9]+/', '',$rev);
147 //$this->repo->impl()->debug = 1;
148 $fh = $this->repo->impl()->git('diff', '--numstat' , "{$this->release}..{$rev}", '--', "");
149 // returns ADDED \t REMOVED \t NAME (might include rename/etc. info)
152 while (false !== ($line = fgets($fh))) {
154 $ar = explode("\t", trim($line));
158 'filename' => $ar[2],
171 function preview($rev)
173 // list the files that have changed..
174 // in theory you could click a number of them and only merge those changes..
175 // need to do a git diff.. and just get a list of files..
177 $rev = preg_replace('/[^a-z0-9]+/', '',$rev);
178 //$this->repo->impl()->debug = 1;
180 if (!empty($_POST['files'])) {
181 $files = json_decode($_POST['files']);
185 $fh = $this->repo->impl()->git('diff', "-w", "{$this->release}..{$rev}", '--', $files);
187 echo '<PRE>' . htmlspecialchars(stream_get_contents($fh)) . '</PRE>';
197 $wd = $this->repo->getWorkingCopy();
198 // $wd->checkout($this->release);
199 // generate the patch
201 // commit with message..