Fix #5661 - MTrack - daily email large and no branch
[web.mtrack] / MTrack / SCM / Git / Repo.php
index 2b7b314..402e45a 100644 (file)
@@ -8,6 +8,8 @@ class MTrack_SCM_Git_Repo extends MTrack_Repo
   protected $tags = null;
   public $gitdir = null;
 
+  public $debug = false;
+
   public function getSCMMetaData() {
     return array(
       'name' => 'Git',
@@ -15,17 +17,17 @@ class MTrack_SCM_Git_Repo extends MTrack_Repo
     );
   }
 
-  function __construct($id = null) {
+    function __construct($ar = null) {
         
-        parent::__construct($id);
-        if ($id !== null) {
+        parent::__construct($ar);
+        if ($ar !== null) {
           /* transparently handle bare vs. non bare repos */
-          $this->gitdir = $this->repopath;
-          if (is_dir("$this->repopath/.git")) {
-            $this->gitdir .= "/.git";
-          }
+            $this->gitdir = $this->repopath;
+            if (is_dir("$this->repopath/.git")) {
+                $this->gitdir .= "/.git";
+            }
         }
-  }
+    }
 
   function getServerURL() {
     $url = parent::getServerURL();
@@ -49,7 +51,7 @@ class MTrack_SCM_Git_Repo extends MTrack_Repo
       putenv("GIT_AUTHOR_EMAIL=$who");
 
       if ($r->clonedfrom) {
-        $S = MTrackRepo::loadById($r->clonedfrom);
+        $S = MTrack_Repo::loadById($r->clonedfrom);
 
         $stm = MTrackSCM::run('git', 'read',
             array('clone', '--bare', $S->repopath, $r->repopath));
@@ -214,8 +216,17 @@ HOOK;
      * 
      * @param  string path (can be empty - eg. '')
      * @param  {number|date} limit  how many to fetch
+     *
+     *      -- prefered args:
+     *          
      * @param  {string} object = eg. rev|tag|branch  (use 'rev' here and ident=HASH to retrieve a speific revision
      * @param  {string} ident = 
+     *
+     * Example:
+     *   - fetch on revision?:  '.',1,'rev','xxxxxxxxxx'
+     *
+     *
+     * range... object ='rev' ident ='master..release'
      * 
      */
     public function history($path, $limit = null, $object = null, $ident = null)
@@ -231,12 +242,26 @@ HOOK;
         } else {
             $args[] = "master";
         }
-        
-    
+     
         if ($limit !== null) {
             if (is_int($limit)) {
                 $args[] = "--max-count=$limit";
-            } else {
+            } else if (is_array($limit) && isset($limit[0]) && isset($limit[1])) {
+                
+                $args[] = "--skip={$limit[0]} --max-count={$limit[1]}";
+                
+                
+            /// oh what a horible hack.. - bad api design here.
+            } else if (is_array($limit) ) {
+                foreach($limit as $k=>$v) {
+                     
+                    $args[] = ($k == '-') ? $v : ('--'. $k .'='. $v);
+                    
+                }
+                 
+            } else if (strpos($limit,'..') !== false ) {
+                 $args[] = $limit;
+            } else {   
                 $args[] = "--since=$limit";
             }
         }
@@ -246,18 +271,22 @@ HOOK;
         $args[] = "--no-abbrev";
         $args[] = "--numstat";
         $args[] = "--date=rfc";
+        $args[] = "--source"; // show the branch..
         
         
         //echo '<PRE>';print_r($args);echo '</PRE>';
         $path = ltrim($path, '/');
-        //print_R(array($args, '--' ,$path));
+        
+        
+        
+        //   print_R(array($args, '--' ,$path));exit;
         $fp = $this->git('log', $args, '--', $path);
 
         $commits = array();
         $commit = null;
         while (true) {
           $line = fgets($fp);
-          if ($line === false) {
+          if ($line === false) { //end of file..
             if ($commit !== null) {
               $commits[] = $commit;
             }
@@ -305,11 +334,11 @@ HOOK;
         return $this->git('diff', "$from^..$from", '--', $path);
       }
 
-  public function getWorkingCopy()
-  {
-    require_once 'MTrack/SCM/Git/WorkingCopy.php';
-    return new MTrack_SCM_Git_WorkingCopy($this);
-  }
+    public function getWorkingCopy()
+    {
+        require_once 'MTrack/SCM/Git/WorkingCopy.php';
+        return new MTrack_SCM_Git_WorkingCopy($this);
+    }
 
   public function getRelatedChanges($revision) // pretty nasty.. could end up with 1000's of changes..
   {
@@ -334,31 +363,42 @@ HOOK;
     return array($parents, $kids);
   }
 
-  function git()
-  {
-    $args = func_get_args();
-    $a = array(
-      "--git-dir=$this->gitdir"
-    );
-    
-    
-    
-    if ($this->gitdir != $this->repopath) {
-    //    print_r(array($this->gitdir , $this->repopath));
-        
-      //$a[] = "--work-tree=$this->repopath";
+    function git()
+    {
+           $args = func_get_args();
+          $a = array(
+            "--git-dir=$this->gitdir"
+          );
+          
+          
+          
+          if ($this->gitdir != $this->repopath) {
+          //    print_r(array($this->gitdir , $this->repopath));
+              
+            //$a[] = "--work-tree=$this->repopath";
+          }
+          foreach ($args as $arg) {
+              if (is_array($arg)) {
+                  $a = array_merge($a, $arg);
+                  continue;
+              }
+              $a[] = $arg;
+          }
+          if ($this->debug) { 
+              var_dump('git ' . join (' ' , $a));
+            //  die("oops");
+          }
+          //echo "git " . implode(" " , $a) . "\n";
+          return MTrackSCM::run('git', 'read', $a);
     }
-    foreach ($args as $arg) {
-        if (is_array($arg)) {
-            $a = array_merge($a, $arg);
-            continue;
-        }
-        $a[] = $arg;
+  
+   
+    function commitLogToEvent($str) {
+        require_once 'MTrack/SCM/Git/Event.php';
+        return  MTrack_SCM_Git_Event::newFromCommit($str,$this);
     }
-    var_dump('git ' . join (' ' , $a));
-    //print_r($a);
-    return MTrackSCM::run('git', 'read', $a);
-  }
+
+  
 }