MTrack/SCM/Git/Repo.php
[web.mtrack] / MTrack / SCM / Git / Repo.php
index baa9c84..633f090 100644 (file)
@@ -216,6 +216,9 @@ 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 = 
      *
@@ -239,15 +242,26 @@ HOOK;
         } else {
             $args[] = "master";
         }
-        
+       
     
         if ($limit !== null) {
             if (is_int($limit)) {
                 $args[] = "--max-count=$limit";
-            } else if (is_array($limit)) {
+            } else if (is_array($limit) && isset($limit[0]) && isset($limit[2])) {
                 
                 $args[] = "--skip={$limit[0]} --max-count={$limit[1]}";
+                
+                
+            /// oh what a horible hack.. - bad api design here.
+            } else if (is_object($limit) ) {
+                foreach((array)$limit as $k=>$v) {
+                     
+                    $args[] = ($k = '-') ? $v : ('--'. $k .'='. $v);
+                    
+                }
+                 
             } else {
+                    
                 $args[] = "--since=$limit";
             }
         }
@@ -261,7 +275,10 @@ HOOK;
         
         //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();
@@ -316,11 +333,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..
   {
@@ -345,33 +362,34 @@ 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";
-        }
-        foreach ($args as $arg) {
-            if (is_array($arg)) {
-                $a = array_merge($a, $arg);
-                continue;
-            }
-            $a[] = $arg;
-        }
-        if ($this->debug) { 
-            var_dump('git ' . join (' ' , $a));
-        }
-        //print_r($a);
-        return MTrackSCM::run('git', 'read', $a);
-  }
+    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);
+    }
   
    
     function commitLogToEvent($str) {