MTrack/SCM.php
[web.mtrack] / MTrack / SCM.php
index cb624c0..c0e0188 100644 (file)
@@ -65,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);
             }
         }
         
@@ -78,9 +78,9 @@ abstract class MTrackSCM
             $FORKS[$cmd] = 0;
         }
         $FORKS[$cmd]++;
-        echo  $cmd;
+        //echo  $cmd;
         // debugging....
-        if (false) {
+        if (true) {
             if (php_sapi_name() == 'cli') {
                 echo $cmd, "\n";
             } else {
@@ -104,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 = '';
     /*
@@ -251,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;
+    }
 
      
 }