]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow setting lint cache granularity
authorvrana <jakubv@fb.com>
Thu, 22 Nov 2012 02:38:24 +0000 (18:38 -0800)
committervrana <jakubv@fb.com>
Mon, 3 Dec 2012 23:30:06 +0000 (15:30 -0800)
Summary:
We can add `GRANULARITY_DIRECTORY` and `GRANULARITY_REPOSITORY` later.
Repository granularity may use current commit + changes.
Directory would need to use hashes of all files in dir which would be quite expensive.

Test Plan:
  $ echo '<?php class A extends B {}' > A.php
  $ arc lint --cache 1
  $ arc lint --cache 1
  $ echo '<?php class B {}' > B.php
  $ arc lint --cache 1
  $ arc lint --cache 1
  $ rm B.php
  $ arc lint --cache 1
  $ arc lint --cache 1

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D4021

src/lint/ArcanistLintMessage.php
src/lint/engine/ArcanistLintEngine.php
src/lint/linter/ArcanistLinter.php
src/lint/linter/ArcanistPhutilLibraryLinter.php
src/workflow/ArcanistLintWorkflow.php

index cce74e5e3211a99760dcee34f4a577a9eaa5210f..25f193d74a2842128f9969291e19ee7d50d9b0df 100644 (file)
@@ -19,6 +19,7 @@ final class ArcanistLintMessage {
   protected $appliedToDisk;
   protected $dependentMessages = array();
   protected $obsolete;
+  protected $uncacheable;
 
   public static function newFromDictionary(array $dict) {
     $message = new ArcanistLintMessage();
@@ -179,6 +180,15 @@ final class ArcanistLintMessage {
     return $this->appliedToDisk;
   }
 
+  public function setUncacheable($bool) {
+    $this->uncacheable = $bool;
+    return $this;
+  }
+
+  public function isUncacheable() {
+    return $this->uncacheable;
+  }
+
   public function setDependentMessages(array $messages) {
     assert_instances_of($messages, 'ArcanistLintMessage');
     $this->dependentMessages = $messages;
index cbf7670a8c3700596712cb898256a35bf3a40bb9..8d4845f2ee1f4bf08c62e3f55225240a2fd41df7 100644 (file)
@@ -198,6 +198,8 @@ abstract class ArcanistLintEngine {
         }
         $paths = $linter->getPaths();
 
+        $cache_granularity = $linter->getCacheGranularity();
+
         foreach ($paths as $key => $path) {
           // Make sure each path has a result generated, even if it is empty
           // (i.e., the file has no lint messages).
@@ -205,9 +207,10 @@ abstract class ArcanistLintEngine {
           if (isset($stopped[$path])) {
             unset($paths[$key]);
           }
-          // TODO: Some linters work with the whole directory.
           if (isset($this->cachedResults[$path][$this->cacheVersion])) {
-            unset($paths[$key]);
+            if ($cache_granularity == ArcanistLinter::GRANULARITY_FILE) {
+              unset($paths[$key]);
+            }
           }
         }
         $paths = array_values($paths);
@@ -231,6 +234,9 @@ abstract class ArcanistLintEngine {
           if (!$this->isRelevantMessage($message)) {
             continue;
           }
+          if ($cache_granularity != ArcanistLinter::GRANULARITY_FILE) {
+            $message->setUncacheable(true);
+          }
           $result = $this->getResultForPath($message->getPath());
           $result->addMessage($message);
         }
index 0c20fab94e60d6490f19b44bddf5627a6f105cfb..909aa71be6bd0380aa2438890db97c8d325f5329 100644 (file)
@@ -8,6 +8,11 @@
  */
 abstract class ArcanistLinter {
 
+  const GRANULARITY_FILE = 1;
+  const GRANULARITY_DIRECTORY = 2;
+  const GRANULARITY_REPOSITORY = 3;
+  const GRANULARITY_GLOBAL = 4;
+
   protected $paths  = array();
   protected $data   = array();
   protected $engine;
@@ -211,4 +216,8 @@ abstract class ArcanistLinter {
     return array();
   }
 
+  public function getCacheGranularity() {
+    return self::GRANULARITY_FILE;
+  }
+
 }
index c7a31e523a8dceca17daf16ec772458fae595ab5..7b7ebe764b0b7392c4bee7a76bcdf18c4c6f1342 100644 (file)
@@ -171,4 +171,9 @@ final class ArcanistPhutilLibraryLinter extends ArcanistLinter {
   public function lintPath($path) {
     return;
   }
+
+  public function getCacheGranularity() {
+    return self::GRANULARITY_GLOBAL;
+  }
+
 }
index 10e8a37b4394b8da77ce916b8a0e3aeebe0e9f29..fce3eccb1f762863b5ecb5181a7115fdeaa02e8c 100644 (file)
@@ -192,9 +192,14 @@ EOTEXT
     if ($this->getArgument('cache')) {
       $cache = $this->readScratchJSONFile('lint-cache.json');
       $cache = idx($cache, $this->getCacheKey(), array());
+      $cache = array_intersect_key($cache, array_flip($paths));
       $cached = array();
       foreach ($cache as $path => $messages) {
-        $messages = idx($messages, md5_file($engine->getFilePathOnDisk($path)));
+        $abs_path = $engine->getFilePathOnDisk($path);
+        if (!Filesystem::pathExists($abs_path)) {
+          continue;
+        }
+        $messages = idx($messages, md5_file($abs_path));
         if ($messages !== null) {
           $cached[$path] = $messages;
         }
@@ -400,10 +405,17 @@ EOTEXT
           unset($cached[$path]);
           continue;
         }
-        $hash = md5_file($engine->getFilePathOnDisk($path));
+        $abs_path = $engine->getFilePathOnDisk($path);
+        if (!Filesystem::pathExists($abs_path)) {
+          continue;
+        }
+        $hash = md5_file($abs_path);
         $version = $result->getCacheVersion();
         $cached[$path] = array($hash => array($version => array()));
         foreach ($result->getMessages() as $message) {
+          if ($message->isUncacheable()) {
+            continue;
+          }
           if (!$message->isPatchApplied()) {
             $cached[$path][$hash][$version][] = $message->toDictionary();
           }