]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve handling of `--background` with `--base`
authorepriestley <git@epriestley.com>
Tue, 2 Oct 2012 18:01:49 +0000 (11:01 -0700)
committerepriestley <git@epriestley.com>
Tue, 2 Oct 2012 18:01:49 +0000 (11:01 -0700)
Summary:
Currently, we run `runDiffSetupBasics()` //after// splitting off background lint and unit tests. However, this means `--base` and any explicit revision name (like "HEAD^") will not be parsed, so the call to `getRelativeCommit()` in order to generate `arc lint --rev XXX` will fail or not work as expected, because it will ignore any arguments.

Instead, parse `--base`, explicit revisions, and other repository API arguments before doing lint and unit tests.

Test Plan:
  - Set global config for `base` to `arc:amended, git:branch-unique(origin/master)`.
  - Created a commit on master.
  - Ran `arc diff HEAD^`.
    - Before this change, the command fails with "Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly." when it attempts to run lint, because the `HEAD^` argument is never parsed. After
    - After this change, the command succeeds.

Reviewers: vrana

Reviewed By: vrana

CC: aran
Differential Revision: https://secure.phabricator.com/D3574

src/workflow/ArcanistDiffWorkflow.php

index 70496bbac1bd248a0e21a6394ace27bf0731931e..1f9fabd9a577d459cb8c312826cd3182a658c80d 100644 (file)
@@ -368,6 +368,8 @@ EOTEXT
   public function run() {
     $this->console = PhutilConsole::getConsole();
 
+    $this->runRepositoryAPISetup();
+
     if ($this->getArgument('no-diff')) {
       $this->removeScratchFile('diff-result.json');
       $data = $this->runLintUnit();
@@ -387,6 +389,7 @@ EOTEXT
       if (!PhutilConsoleFormatter::getDisableANSI()) {
         array_unshift($argv, '--ansi');
       }
+
       $lint_unit = new ExecFuture(
         'php %s --recon diff --no-diff %Ls',
         phutil_get_library_root('arcanist').'/../scripts/arcanist.php',
@@ -541,29 +544,33 @@ EOTEXT
     return 0;
   }
 
-  private function runDiffSetupBasics() {
-    if ($this->requiresRepositoryAPI()) {
-      $repository_api = $this->getRepositoryAPI();
-      if ($this->getArgument('less-context')) {
-        $repository_api->setDiffLinesOfContext(3);
-      }
+  private function runRepositoryAPISetup() {
+    if (!$this->requiresRepositoryAPI()) {
+      return;
+    }
 
-      $repository_api->setBaseCommitArgumentRules(
-        $this->getArgument('base', ''));
+    $repository_api = $this->getRepositoryAPI();
+    if ($this->getArgument('less-context')) {
+      $repository_api->setDiffLinesOfContext(3);
+    }
 
-      if ($repository_api->supportsRelativeLocalCommits()) {
+    $repository_api->setBaseCommitArgumentRules(
+      $this->getArgument('base', ''));
 
-        // 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).
+    if ($repository_api->supportsRelativeLocalCommits()) {
 
-        $relative = $this->getArgument('paths');
-        if ($relative) {
-          $repository_api->parseRelativeLocalCommit($relative);
-        }
+      // 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);
       }
     }
+  }
 
+  private function runDiffSetupBasics() {
     $output_json = $this->getArgument('json');
     if ($output_json) {
       // TODO: We should move this to a higher-level and put an indirection
@@ -1230,6 +1237,7 @@ EOTEXT
         $argv[] = '--rev';
         $argv[] = $repository_api->getRelativeCommit();
       }
+
       $lint_workflow = $this->buildChildWorkflow('lint', $argv);
 
       if ($this->shouldAmend()) {