Merge branch 'master' of /home/git/private/web.mtrack
[web.mtrack] / MTrack / SCM.php
index 8630401..817a1af 100644 (file)
@@ -46,12 +46,16 @@ abstract class MTrackSCM
     {
         global $FORKS; //??? why?
         
-        static $tools; // we cache the lookups... - we could use the config for this... (as per original..)
-                        // but that would only be needed or realy heavily loaded sites.
+        static $tools; // we cache the lookups...
+                //- we could use the config for this... (as per original..)
+                // but that would only be needed or realy heavily loaded sites.
+                
         
         require_once 'System.php';
         $tool = isset($tools[$toolname]) ? $tools[$toolname] :  System::which($toolname);
         $tools[$toolname] = $tool;
+        
+        
         if (empty($tool)) {
             throw new Exception("Could not find '$toolname'");
         }
@@ -61,12 +65,12 @@ abstract class MTrackSCM
         
         foreach ($args as $arg) {
             if (!is_array($arg)) {
-                $cmd .= ' ' . escapeshellarg($arg);
+                $cmd .= ' ' . MTrackSCM::escapeshellarg($arg);
                 continue;
             }
             
             foreach ($arg as $a) {
-                $cmd .= ' ' . escapeshellarg($a);
+                $cmd .= ' ' . MTrackSCM::escapeshellarg($a);
             }
         }
         
@@ -74,7 +78,7 @@ abstract class MTrackSCM
             $FORKS[$cmd] = 0;
         }
         $FORKS[$cmd]++;
-        
+        //echo  $cmd;
         // debugging....
         if (false) {
             if (php_sapi_name() == 'cli') {
@@ -100,8 +104,18 @@ abstract class MTrackSCM
         }
     }
     
-    
-    
+    static function escapeshellarg($a) {
+        if (preg_match('/\-[a-z0-9]+$/i', $a)) {
+            return $a; // raw -a
+        }
+        if (preg_match('/\-\-[a-z0-9]+=/i', $a)) {
+            $lr = explode('=', $a,2);
+            return $lr[0].'=' . escapeshellarg($lr[1]); // raw -a
+        }
+        return escapeshellarg($a);
+        
+        
+    }
     
     public $repopath = '';
     /*
@@ -116,7 +130,7 @@ abstract class MTrackSCM
         list($owner, $type) = $bits;
         $repo = "$owner/$type";
         
-        $r = MTrackRepo::loadByName($repo);
+        $r = MTrack_Repo::loadByName($repo);
         if (!$r) {
           throw new Exception("invalid repo $repo");
         }
@@ -232,8 +246,8 @@ abstract class MTrackSCM
     
   
   /* takes an MTrackSCM as a parameter because in some bootstrapping
-   * cases, we're actually MTrackRepo and not the end-class.
-   * MTrackRepo calls the end-class method and passes itself in for
+   * cases, we're actually MTrack_Repo and not the end-class.
+   * MTrack_Repo calls the end-class method and passes itself in for
    * context */
   public function reconcileRepoSettings(MTrackSCM $r) {
     throw new Exception(
@@ -247,32 +261,37 @@ abstract class MTrackSCM
     return self::makeDisplayName($this);
   }
 
-  public function resolveRevision($rev, $object, $ident) {
-      if ($rev !== null) {
-        return $rev;
-      }
-      if ($object === null) {
-        return null;
-      }
-      switch ($object) {
-        case 'rev':
-          $rev = $ident;
-          break;
-        case 'branch':
-          $branches = $this->getBranches();
-           $rev = isset($branches[$ident]) ? $branches[$ident] : null;
-          break;
-        case 'tag':
-          $tags = $this->getTags();
-          $rev = isset($tags[$ident]) ? $tags[$ident] : null;
-          break;
-      }
-      if ($rev === null) {
-        throw new Exception(
-          "don't know which revision to use ($rev,$object,$ident)");
-      }
-    return $rev;
-  }
+    public function resolveRevision($rev, $object, $ident)
+    {
+        if ($rev !== null) {
+          return $rev;
+        }
+        
+        if ($object === null) {
+          return null;
+        }
+        
+        switch ($object) {
+            case 'rev':
+                $rev = $ident;
+                break;
+            
+            case 'branch':
+                $branches = $this->getBranches();
+                $rev = isset($branches[$ident]) ? $branches[$ident] : null;
+                break;
+            
+            case 'tag':
+              $tags = $this->getTags();
+              $rev = isset($tags[$ident]) ? $tags[$ident] : null;
+              break;
+        }
+        if ($rev === null) {
+          throw new Exception(
+            "don't know which revision to use ($rev,$object,$ident)");
+        }
+      return $rev;
+    }
 
      
 }