]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Make arcanist more flexible about SVN base revisions
authorepriestley <epriestley@javelinjs.com>
Wed, 23 Feb 2011 20:06:22 +0000 (12:06 -0800)
committerepriestley <epriestley@javelinjs.com>
Wed, 23 Feb 2011 20:06:22 +0000 (12:06 -0800)
Summary: When running "arc diff" in a mixed-base-revision working copy, we
prevent the operation. Relax this restriction so that having a different root
revision is okay, so long as all affected files share the same revision. This
facilitates multiple similar edits without updates.

Test Plan: Reverted a file to an older revision in an SVN working copy, ran
"arc diff", was rejected. Applied patch, ran "arc diff", diff went through and
was recorded with the right SVN base revision in the database.

Reviewers:

CC:

src/repository/api/subversion/ArcanistSubversionAPI.php
src/workflow/diff/ArcanistDiffWorkflow.php

index 481aecd5d5ed8c5b4704e889c4c63d6ae1a7d52e..7d4cef26261a0b8baf4e2622cf9cdda5d513dabb 100644 (file)
@@ -29,6 +29,8 @@ class ArcanistSubversionAPI extends ArcanistRepositoryAPI {
 
   protected $svnInfoRaw = array();
   protected $svnDiffRaw = array();
+  
+  private $svnBaseRevisionNumber;
 
   public function getSourceControlSystemName() {
     return 'svn';
@@ -161,7 +163,20 @@ class ArcanistSubversionAPI extends ArcanistRepositoryAPI {
 
   public function getSourceControlBaseRevision() {
     $info = $this->getSVNInfo('/');
-    return $info['URL'].'@'.$info['Revision'];
+    return $info['URL'].'@'.$this->getSVNBaseRevisionNumber();
+  }
+  
+  public function getSVNBaseRevisionNumber() {
+    if ($this->svnBaseRevisionNumber) {
+      return $this->svnBaseRevisionNumber;
+    }
+    $info = $this->getSVNInfo('/');
+    return $info['Revision'];
+  }
+  
+  public function overrideSVNBaseRevisionNumber($effective_base_revision) {
+    $this->svnBaseRevisionNumber = $effective_base_revision;
+    return $this;
   }
 
   public function getBranchName() {
index f31d62798101a18ebe2aec44bba01c1a0bd4a585..a1d75ef510af6902c2bb0dd1c6db144a698c4554 100644 (file)
@@ -201,21 +201,6 @@ EOTEXT
 
     $parent = null;
 
-    $base_revision = $repository_api->getSourceControlBaseRevision();
-    $base_path     = $repository_api->getSourceControlPath();
-    if ($repository_api instanceof ArcanistGitAPI) {
-      $info = $this->getGitParentLogInfo();
-      if ($info['parent']) {
-        $parent = $info['parent'];
-      }
-      if ($info['base_revision']) {
-        $base_revision = $info['base_revision'];
-      }
-      if ($info['base_path']) {
-        $base_path = $info['base_path'];
-      }
-    }
-
     $paths = $this->generateAffectedPaths();
 
     $lint_result = $this->runLint($paths);
@@ -256,6 +241,23 @@ EOTEXT
       $unit = 'none';
     }
 
+    // NOTE: This has to happen after generateChanges(), since it may overwrite
+    // the SVN effective base revision.
+    $base_revision = $repository_api->getSourceControlBaseRevision();
+    $base_path     = $repository_api->getSourceControlPath();
+    if ($repository_api instanceof ArcanistGitAPI) {
+      $info = $this->getGitParentLogInfo();
+      if ($info['parent']) {
+        $parent = $info['parent'];
+      }
+      if ($info['base_revision']) {
+        $base_revision = $info['base_revision'];
+      }
+      if ($info['base_path']) {
+        $base_path = $info['base_path'];
+      }
+    }
+
     $diff = array(
       'changes'                   => $change_list,
       'sourceMachine'             => php_uname('n'),
@@ -505,26 +507,31 @@ EOTEXT
       }
 
       if ($bases) {
-        // We have at least one path which isn't new.
-        $repository_info = $repository_api->getSVNInfo('/');
-        $bases['.'] = $repository_info['Revision'];
-        if ($bases['.']) {
-          $rev = $bases['.'];
-          foreach ($bases as $path => $baserev) {
-            if ($baserev !== $rev) {
-              $revlist = array();
-              foreach ($bases as $path => $baserev) {
-                $revlist[] = "    Revision {$baserev}, {$path}";
-              }
-              $revlist = implode("\n", $revlist);
-              throw new ArcanistUsageException(
-                "Base revisions of changed paths are mismatched. Update all ".
-                "paths to the same base revision before creating a diff: ".
-                "\n\n".
-                $revlist);
+        $rev = reset($bases);
+        foreach ($bases as $path => $baserev) {
+          if ($baserev !== $rev) {
+            $revlist = array();
+            foreach ($bases as $path => $baserev) {
+              $revlist[] = "    Revision {$baserev}, {$path}";
             }
+            $revlist = implode("\n", $revlist);
+            throw new ArcanistUsageException(
+              "Base revisions of changed paths are mismatched. Update all ".
+              "paths to the same base revision before creating a diff: ".
+              "\n\n".
+              $revlist);
           }
         }
+        
+        // If you have a change which affects several files, all of which are
+        // at a consistent base revision, treat that revision as the effective
+        // base revision. The use case here is that you made a change to some
+        // file, which updates it to HEAD, but want to be able to change it
+        // again without updating the entire working copy. This is a little
+        // sketchy but it arises in Facebook Ops workflows with config files and
+        // doesn't have any real material tradeoffs (e.g., these patches are
+        // perfectly applyable).
+        $repository_api->overrideSVNBaseRevisionNumber($rev);
       }
 
       $changes = $parser->parseSubversionDiff(