]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Set relative commit early in "arc diff"
authorepriestley <git@epriestley.com>
Fri, 23 Mar 2012 00:22:52 +0000 (17:22 -0700)
committerepriestley <git@epriestley.com>
Fri, 23 Mar 2012 00:22:52 +0000 (17:22 -0700)
Summary:
In Mercurial, we figure out if the working copy is dirty with "hg diff", and do a somewhat expensive merge-base / outgoing operation if the relative commit isn't set. We can set the relative commit earlier and avoid some extra work.

We also may incorrectly cache this state (diff from merge-base of outgoing to tip) and pass the wrong rev and file dirty list to the linters.

Test Plan: Made commits which changed (A, B) and then (A). Ran "arc diff tip^". Before this change, observed full outgoing + merge base resolve and both "A" and "B" passed to lint. Observed execution of fewer commands and lint executing against "A" only after this change.

Reviewers: Makinde, btrahan

Reviewed By: Makinde

CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1998

src/repository/api/mercurial/ArcanistMercurialAPI.php
src/workflow/diff/ArcanistDiffWorkflow.php

index 74a21c4e419d06d7be03b179621b0f91fb0ff314..57c256f2e8ec1f0691b015c47758e53d1c6410b3 100644 (file)
@@ -84,6 +84,8 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
     }
 
     $this->relativeCommit = $commit;
+    $this->dropCaches();
+
     return $this;
   }
 
@@ -463,9 +465,7 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
   }
 
   private function getDiffToRevision() {
-
-    // Clear status cache since it's now bogus.
-    $this->status = null;
+    $this->dropCaches();
 
     if ($this->includeDirectoryStateInDiffs) {
       // This is a magic Mercurial revision name which means "current
@@ -476,4 +476,9 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
     }
   }
 
+  private function dropCaches() {
+    $this->status = null;
+    $this->localCommitInfo = null;
+  }
+
 }
index 4041aef8531ee03e640eee0665c803ed2b4185c7..401f7edde7696b322284f0f0dca242be21511e42 100644 (file)
@@ -497,6 +497,18 @@ EOTEXT
       if ($this->getArgument('less-context')) {
         $repository_api->setDiffLinesOfContext(3);
       }
+
+      if ($repository_api->supportsRelativeLocalCommits()) {
+
+        // Parse the relative commit as soon as we can, to avoid generating
+        // caches we need to drop later and expensive discovery operations
+        // (particularly in Mercurial).
+
+        $relative = $this->getArgument('paths');
+        if ($relative) {
+          $repository_api->parseRelativeLocalCommit($relative);
+        }
+      }
     }
 
     $output_json = $this->getArgument('json');
@@ -622,8 +634,6 @@ EOTEXT
       }
 
     } else if ($repository_api->supportsRelativeLocalCommits()) {
-      $repository_api->parseRelativeLocalCommit(
-        $this->getArgument('paths', array()));
       $paths = $repository_api->getWorkingCopyStatus();
     } else {
       throw new Exception("Unknown VCS!");