]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Arc patch - upgrade "same base rev" check to "does this commit exist in the working...
authorBob Trahan <bob.trahan@gmail.com>
Wed, 7 Mar 2012 21:02:53 +0000 (13:02 -0800)
committerBob Trahan <bob.trahan@gmail.com>
Wed, 7 Mar 2012 21:02:53 +0000 (13:02 -0800)
Summary: good title

Test Plan: ran "arc patch DX" a bunch

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, epriestley
Maniphest Tasks: T892

Differential Revision: https://secure.phabricator.com/D1789

src/repository/api/base/ArcanistRepositoryAPI.php
src/repository/api/git/ArcanistGitAPI.php
src/repository/api/mercurial/ArcanistMercurialAPI.php
src/repository/api/subversion/ArcanistSubversionAPI.php
src/workflow/patch/ArcanistPatchWorkflow.php

index ed7ab1d32cb1bf05d5ca98949ccb73f2409acbea..62657beae2d82e7686b04eea6a47114fe4fe0f87 100644 (file)
@@ -161,6 +161,10 @@ abstract class ArcanistRepositoryAPI {
     ConduitClient $conduit,
     array $query);
 
+  public function hasLocalCommit($commit) {
+    throw new ArcanistCapabilityNotSupportedException($this);
+  }
+
   public function getCommitMessageForRevision($revision) {
     throw new ArcanistCapabilityNotSupportedException($this);
   }
index bb9ac71a92ce2210767c6a3c62b71690798e7e17..1adcfef390d8584b44d641663852eefdf762b366 100644 (file)
@@ -551,6 +551,13 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
     return true;
   }
 
+  public function hasLocalCommit($commit) {
+    list($err) = $this->execManualLocal(
+      'merge-base %s HEAD',
+      $commit);
+    return !$err;
+  }
+
   public function parseRelativeLocalCommit(array $argv) {
     if (count($argv) == 0) {
       return;
index 9392299ac459c58e66fd3bdaeeb1261dfe47d305..04daa133389698a7ac085348472ebd28bc1e3063 100644 (file)
@@ -71,12 +71,10 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
   }
 
   public function setRelativeCommit($commit) {
-    list($err) = $this->execManualLocal('id -ir %s', $commit);
-    if ($err) {
+    if (!$this->hasLocalCommit($commit)) {
       throw new ArcanistUsageException(
         "Commit '{$commit}' is not a valid Mercurial commit identifier.");
     }
-
     $this->relativeCommit = $commit;
     return $this;
   }
@@ -338,6 +336,11 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
     return true;
   }
 
+  public function hasLocalCommit($commit) {
+    list($err) = $this->execManualLocal('id -ir %s', $commit);
+    return !$err;
+  }
+
   public function parseRelativeLocalCommit(array $argv) {
     if (count($argv) == 0) {
       return;
index 55ce4379ebf2edc0a663afbfbc87e2007947a12b..f476b6f1612ffab7dca9daa7e10ad2f045e6dfc9 100644 (file)
@@ -502,6 +502,10 @@ EODIFF;
     return false;
   }
 
+  public function hasLocalCommit($commit) {
+    return false;
+  }
+
   public function getWorkingCopyRevision() {
     return $this->getSourceControlBaseRevision();
   }
index de4d025bed620127c096266563e450a6c07423df..3f9fd0ff931dff17583f0c986b39b7fa94a48fd2 100644 (file)
@@ -687,26 +687,26 @@ EOTEXT
 
     // Check to see if the bundle's base revision matches the working copy
     // base revision
-    $bundle_base_rev = $bundle->getBaseRevision();
-    if (empty($bundle_base_rev)) {
-      // this means $source is SOURCE_PATCH || SOURCE_BUNDLE w/ $version < 2
-      // they don't have a base rev so just do nothing
-    } else {
-      $repository_api = $this->getRepositoryAPI();
-      $source_base_rev = $repository_api->getWorkingCopyRevision();
-
-      if ($source_base_rev != $bundle_base_rev) {
+    $repository_api = $this->getRepositoryAPI();
+    if ($repository_api->supportsRelativeLocalCommits()) {
+      $bundle_base_rev = $bundle->getBaseRevision();
+      if (empty($bundle_base_rev)) {
+        // this means $source is SOURCE_PATCH || SOURCE_BUNDLE w/ $version < 2
+        // they don't have a base rev so just do nothing
+        $commit_exists = true;
+      } else {
+        $commit_exists =
+          $repository_api->hasLocalCommit($bundle_base_rev);
+      }
+      if (!$commit_exists) {
         // we have a problem...! lots of work because we need to ask
         // differential for revision information for these base revisions
         // to improve our error message.
         $bundle_base_rev_str = null;
+        $source_base_rev     = $repository_api->getWorkingCopyRevision();
         $source_base_rev_str = null;
 
-        // SVN doesn't store these hashes, so we're basically done already
-        // and will have a relatively "lame" error message
-        if ($repository_api instanceof ArcanistSubversionAPI) {
-          $hash_type = null;
-        } else if ($repository_api instanceof ArcanistGitAPI) {
+        if ($repository_api instanceof ArcanistGitAPI) {
           $hash_type = ArcanistDifferentialRevisionHash::HASH_GIT_COMMIT;
         } else if ($repository_api instanceof ArcanistMercurialAPI) {
           $hash_type = ArcanistDifferentialRevisionHash::HASH_MERCURIAL_COMMIT;
@@ -738,8 +738,8 @@ EOTEXT
 
         $ok = phutil_console_confirm(
           "This diff is against commit {$bundle_base_rev_str}, but the ".
-          "working copy is at {$source_base_rev_str}.  ".
-          "Still try to apply it?",
+          "commit is nowhere in the working copy. Try to apply it against ".
+          "the current working copy state? ({$source_base_rev_str})",
           $default_no = false
         );
         if (!$ok) {