Fix #5661 - MTrack - daily email large and no branch
[Pman.MTrack] / DataObjects / Mtrack_repos.php
index 03f6621..60d01bf 100644 (file)
@@ -439,7 +439,19 @@ class Pman_MTrack_DataObjects_Mtrack_repos extends DB_DataObject
     }
     
     
-    
+    function branchObject($n)
+    {
+        // create or return branch dataobject
+        $b = DB_DataObject::factory('mtrack_repos_branch');
+        $b->repo_id = $this->id;
+        $b->name = $n;
+        if ($b->find(true)) {
+            return $b;
+        }
+        $b->insert();
+        return $b;
+        
+    }
     
     // these should really be phased out, and the Controlers use impl()-> directly..
     function getBranches()
@@ -781,12 +793,16 @@ class Pman_MTrack_DataObjects_Mtrack_repos extends DB_DataObject
         
         //print_r($last);exit;
         $body = '';
-     
+        $len = 0;
         foreach($obj->summary as $file=>$who) { 
             $res = $this->impl()->diff($file, $last ? $last->rev : $first->rev, $last ? $first->rev : null);
             //print_r($res);
             //$lines = $this->parseDiff($res);
             $lines = stream_get_contents($res);
+            $len += strlen($lines);
+            if ($len > 2000000) {
+                $lines = "Too large see repo";
+            }
             
             if (preg_match('/\.map$/', $file)) {
                 $lines = "Changed";
@@ -837,23 +853,41 @@ class Pman_MTrack_DataObjects_Mtrack_repos extends DB_DataObject
         
         //$this->impl()->debug=1;
         //print_r(array('since'=> '{'.$start.'}' , 'before' => '{'.$end .'}'));
-        $res = $this->impl()->history('.', array('since'=> '{'.$start.'}' , 'before' => '{'.$end .'}'), $object, $branch);
-         
-        // find the last rev the day before...
-        
+        $res = $this->impl()->history('.', array('since'=> '{'.$start.'}' , 'before' => '{'.$end .'}'), 'rev', '--all');
         
-        
-        $obj = $this->historyToSummary($res, $notify->act_start);
-        if (!$obj) {
-           // echo "History returned nothing";
-            return true;
+        $branches = array();
+        foreach($res as $r) {
+            if (!preg_match('#^refs/heads/.*$#', $r->branch)) {
+                continue;
+            }
+            $br = preg_replace('#^refs/heads/.*$#', $r->branch, '');
+            $branches[$br] = 1;
+                
+        }
+        $objs = array();
+        foreach($branches as $branch=>$one) {
+            
+            
+            $res = $this->impl()->history('.', array('since'=> '{'.$start.'}' , 'before' => '{'.$end .'}'), $object, $branch);
+             
+            // find the last rev the day before...
+            
+            
+             
+            $obj = $this->historyToSummary($res, $notify->act_start);
+            if (!$obj) {
+               // echo "History returned nothing";
+                return true;
+            }
+            $obj->from_dt = $start;
+            $obj->to_dt = $end;
+            $obj->branch = $br;
+            //print_r($obj);exit; 
+         
+            $objs[] = $obj;
         }
-        $obj->from_dt = $start;
-        $obj->to_dt = $end;
+        $ret =   $rcpt->buildMail('repo_daily_changes', array('branches' => $obj));
         
-        //print_r($obj);exit; 
-        $ret =   $rcpt->buildMail('repo_daily_changes', $obj);
-        //print_r($ret);exit;
         return $ret;