]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Move some VCS-specific logic into VCS APIs
authorepriestley <git@epriestley.com>
Thu, 15 Sep 2011 01:44:54 +0000 (18:44 -0700)
committerepriestley <git@epriestley.com>
Thu, 15 Sep 2011 14:39:34 +0000 (07:39 -0700)
Summary:
We have some git-specific logic on main pathways which should be in the API
class, move it around so "arc lint" with an engine works under Mercurial. This
resovles the error @makinde reported:

> PHP Catchable fatal error:  Argument 1 passed to
ArcanistBaseWorkflow::parseGitRelativeCommit() must be an instance of
ArcanistGitAPI, instance of ArcanistMercurialAPI given, called in
/home/makinde/.arc_install/arcanist/src/workflow/lint/ArcanistLintWorkflow.php
on line 131 and defined in
/home/makinde/.arc_install/arcanist/src/workflow/base/ArcanistBaseWorkflow.php
on line 830

Test Plan: Ran "arc diff" in git and hg working copies, plus "arc lint" with a
configured "lint_engine".

Reviewers: Makinde, aran, jungejason, nh, tuomaspelkonen

Reviewed By: Makinde

CC: aran, Makinde
Differential Revision: 935

src/repository/api/base/ArcanistRepositoryAPI.php
src/repository/api/git/ArcanistGitAPI.php
src/repository/api/git/__init__.php
src/repository/api/mercurial/ArcanistMercurialAPI.php
src/repository/api/subversion/ArcanistSubversionAPI.php
src/workflow/base/ArcanistBaseWorkflow.php
src/workflow/base/__init__.php
src/workflow/diff/ArcanistDiffWorkflow.php
src/workflow/lint/ArcanistLintWorkflow.php

index 1a987707f89c0c58c23a8f980c9cc867753b7887..b3031ce1084803e3e85677b7220be08b96c7c7c4 100644 (file)
@@ -159,4 +159,15 @@ abstract class ArcanistRepositoryAPI {
   abstract public function getCurrentFileData($path);
   abstract public function getLocalCommitInformation();
 
+
+  abstract public function supportsRelativeLocalCommits();
+
+  public function parseRelativeLocalCommit(array $argv) {
+    throw new Exception("This VCS does not support relative local commits.");
+  }
+
+  public function getAllLocalChanges() {
+    throw new Exception("This VCS does not support getting all local changes.");
+  }
+
 }
index 17181d76a691de909086100502f2c205b318ba56..db16cd87ece5f8c2ada8b62c389e25a3c518a9ee 100644 (file)
@@ -512,4 +512,37 @@ class ArcanistGitAPI extends ArcanistRepositoryAPI {
     return trim($owner);
   }
 
+  public function supportsRelativeLocalCommits() {
+    return true;
+  }
+
+  public function parseRelativeLocalCommit(array $argv) {
+    if (count($argv) == 0) {
+      return;
+    }
+    if (count($argv) != 1) {
+      throw new ArcanistUsageException("Specify only one commit.");
+    }
+    $base = reset($argv);
+    if ($base == ArcanistGitAPI::GIT_MAGIC_ROOT_COMMIT) {
+      $merge_base = $base;
+    } else {
+      list($err, $merge_base) = exec_manual(
+        '(cd %s; git merge-base %s HEAD)',
+        $this->getPath(),
+        $base);
+      if ($err) {
+        throw new ArcanistUsageException(
+          "Unable to parse git commit name '{$base}'.");
+      }
+    }
+    $this->setRelativeCommit(trim($merge_base));
+  }
+
+  public function getAllLocalChanges() {
+    $diff = $this->getFullGitDiff();
+    $parser = new ArcanistDiffParser();
+    return $parser->parseDiff($diff);
+  }
+
 }
index c225acc7c3025f45badaf33749c5174f8e5c646b..a7fd205dc3f4f3a11973ea2a610b6c738643a9d3 100644 (file)
@@ -6,6 +6,8 @@
 
 
 
+phutil_require_module('arcanist', 'exception/usage');
+phutil_require_module('arcanist', 'parser/diff');
 phutil_require_module('arcanist', 'repository/api/base');
 
 phutil_require_module('phutil', 'future');
index db6fbfa41ee906076fc2995ebd5ac9c307b66555..db78f0b55f766b3a7b5a974d7da9ed51ec690c47 100644 (file)
@@ -374,4 +374,26 @@ class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
     return trim($match[1]);
   }
 
+  public function supportsRelativeLocalCommits() {
+    return true;
+  }
+
+  public function parseRelativeLocalCommit(array $argv) {
+    if (count($argv) == 0) {
+      return;
+    }
+    if (count($argv) != 1) {
+      throw new ArcanistUsageException("Specify only one commit.");
+    }
+    // This does the "hg id" call we need to normalize/validate the revision
+    // identifier.
+    $this->setRelativeCommit(reset($argv));
+  }
+
+  public function getAllLocalChanges() {
+    $diff = $this->getFullMercurialDiff();
+    $parser = new ArcanistDiffParser();
+    return $parser->parseDiff($diff);
+  }
+
 }
index 4616ed353d3ccd7631aef0a05b7ea684a215d208..a91798031c4d7cc5c052e926b22c255a3d8ca130 100644 (file)
@@ -482,4 +482,8 @@ EODIFF;
     return null;
   }
 
+  public function supportsRelativeCommits() {
+    return false;
+  }
+
 }
index 59e5cc8a014ce7d446e4bb9c5ebacc160c35e3b0..6a5a242bd1ef95cd646d1aaddf39ab60f68c6c0a 100644 (file)
@@ -768,6 +768,8 @@ class ArcanistBaseWorkflow {
     $repository_api = $this->getRepositoryAPI();
 
     if ($repository_api instanceof ArcanistSubversionAPI) {
+      // NOTE: In SVN, we don't currently support a "get all local changes"
+      // operation, so special case it.
       if (empty($this->changeCache[$path])) {
         $diff = $repository_api->getRawDiffText($path);
         $parser = new ArcanistDiffParser();
@@ -777,15 +779,15 @@ class ArcanistBaseWorkflow {
         }
         $this->changeCache[$path] = reset($changes);
       }
-    } else {
+    } else if ($repository_api->supportsRelativeLocalCommits()) {
       if (empty($this->changeCache)) {
-        $diff = $repository_api->getFullGitDiff();
-        $parser = new ArcanistDiffParser();
-        $changes = $parser->parseDiff($diff);
+        $changes = $repository_api->getAllLocalChanges();
         foreach ($changes as $change) {
           $this->changeCache[$change->getCurrentPath()] = $change;
         }
       }
+    } else {
+      throw new Exception("Missing VCS support.");
     }
 
     if (empty($this->changeCache[$path])) {
@@ -827,30 +829,6 @@ class ArcanistBaseWorkflow {
     }
   }
 
-  protected function parseGitRelativeCommit(ArcanistGitAPI $api, array $argv) {
-    if (count($argv) == 0) {
-      return;
-    }
-    if (count($argv) != 1) {
-      throw new ArcanistUsageException(
-        "Specify exactly one commit.");
-    }
-    $base = reset($argv);
-    if ($base == ArcanistGitAPI::GIT_MAGIC_ROOT_COMMIT) {
-      $merge_base = $base;
-    } else {
-      list($err, $merge_base) = exec_manual(
-        '(cd %s; git merge-base %s HEAD)',
-        $api->getPath(),
-        $base);
-      if ($err) {
-        throw new ArcanistUsageException(
-          "Unable to parse git commit name '{$base}'.");
-      }
-    }
-    $api->setRelativeCommit(trim($merge_base));
-  }
-
   protected function normalizeRevisionID($revision_id) {
     return ltrim(strtoupper($revision_id), 'D');
   }
index a7a8889fb8afe27c77f1c720d257178271b0b436..a596254a912688411775a1aa53b608b5d39cf291 100644 (file)
@@ -13,7 +13,6 @@ phutil_require_module('arcanist', 'exception/usage/userabort');
 phutil_require_module('arcanist', 'parser/bundle');
 phutil_require_module('arcanist', 'parser/diff');
 phutil_require_module('arcanist', 'parser/diff/change');
-phutil_require_module('arcanist', 'repository/api/git');
 
 phutil_require_module('phutil', 'conduit/client');
 phutil_require_module('phutil', 'console');
index 8fa933906fcb3e9e19b0c143485bcbba859de083..2a25f73a9e4af18e7952d612f40e21d9412ccd69 100644 (file)
@@ -603,17 +603,10 @@ EOTEXT
         }
       }
 
-    } else if ($repository_api instanceof ArcanistGitAPI) {
-      $this->parseGitRelativeCommit(
-        $repository_api,
+    } else if ($repository_api->supportsRelativeLocalCommits()) {
+      $repository_api->parseRelativeLocalCommit(
         $this->getArgument('paths', array()));
       $paths = $repository_api->getWorkingCopyStatus();
-    } else if ($repository_api instanceof ArcanistMercurialAPI) {
-      // TODO: Unify this and the previous block.
-
-      // TODO: Parse the relative commit.
-
-      $paths = $repository_api->getWorkingCopyStatus();
     } else {
       throw new Exception("Unknown VCS!");
     }
index 938b8033253120e578d30f496f25489248954acc..c98d6a263e4b7d34f181140ddc6f809db32743b0 100644 (file)
@@ -125,11 +125,12 @@ EOTEXT
             unset($paths[$path]);
           }
         }
-      } else {
-        $this->parseGitRelativeCommit(
-          $repository_api,
-          $this->getArgument('paths'));
+      } else if ($repository_api->supportsRelativeLocalCommits()) {
+        $repository_api->parseRelativeLocalCommit(
+          $this->getArgument('paths', array()));
         $paths = $repository_api->getWorkingCopyStatus();
+      } else {
+        throw new Exception("Unknown VCS!");
       }
 
       foreach ($paths as $path => $flags) {
@@ -139,7 +140,6 @@ EOTEXT
       }
 
       $paths = array_keys($paths);
-
     } else {
       $paths = $this->getArgument('paths');
       if (empty($paths)) {