]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Respect granularity in reading cached lint messages
authorvrana <jakubv@fb.com>
Wed, 6 Feb 2013 23:27:31 +0000 (15:27 -0800)
committervrana <jakubv@fb.com>
Thu, 14 Feb 2013 19:45:38 +0000 (11:45 -0800)
Summary:
We save repository version to lint cache but ignore it when reading the cache.
Fix it.

Test Plan: Made an error for linter with repo granularity, deleted the error from the cache. Relinted, didn't see the error. Changed another file and relinted, saw the error.

Reviewers: epriestley

Reviewed By: epriestley

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

src/lint/ArcanistLintMessage.php
src/lint/engine/ArcanistLintEngine.php
src/workflow/ArcanistLintWorkflow.php

index 92e2c6b421a598e0462d6e30901d13d593bf2698..cce2ca21cc97e924550700f2f2c60fa5e3fe15ed 100644 (file)
@@ -20,7 +20,7 @@ final class ArcanistLintMessage {
   protected $dependentMessages = array();
   protected $otherLocations = array();
   protected $obsolete;
-  protected $uncacheable;
+  protected $granularity;
 
   public static function newFromDictionary(array $dict) {
     $message = new ArcanistLintMessage();
@@ -38,6 +38,7 @@ final class ArcanistLintMessage {
     if (isset($dict['replacement'])) {
       $message->setReplacementText($dict['replacement']);
     }
+    $message->setGranularity(idx($dict, 'granularity'));
     $message->setOtherLocations(idx($dict, 'locations', array()));
     return $message;
   }
@@ -53,6 +54,7 @@ final class ArcanistLintMessage {
       'description' => $this->getDescription(),
       'original'    => $this->getOriginalText(),
       'replacement' => $this->getReplacementText(),
+      'granularity' => $this->getGranularity(),
       'locations'   => $this->getOtherLocations(),
     );
   }
@@ -196,13 +198,13 @@ final class ArcanistLintMessage {
     return $this->appliedToDisk;
   }
 
-  public function setUncacheable($bool) {
-    $this->uncacheable = $bool;
+  public function setGranularity($granularity) {
+    $this->granularity = $granularity;
     return $this;
   }
 
-  public function isUncacheable() {
-    return $this->uncacheable;
+  public function getGranularity() {
+    return $this->granularity;
   }
 
   public function setDependentMessages(array $messages) {
index a273963af5874651cdef7a9e06ceeb81b019e25f..39f995ead545f39c7d8288c47bce337dde4df997 100644 (file)
@@ -203,8 +203,6 @@ 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).
@@ -215,19 +213,9 @@ abstract class ArcanistLintEngine {
           if (isset($this->cachedResults[$path][$this->cacheVersion])) {
             $cached_result = $this->cachedResults[$path][$this->cacheVersion];
 
-            switch ($cache_granularity) {
-              case ArcanistLinter::GRANULARITY_FILE:
-                $use_cache = true;
-                break;
-              case ArcanistLinter::GRANULARITY_DIRECTORY:
-              case ArcanistLinter::GRANULARITY_REPOSITORY:
-                $repository_version = idx($cached_result, 'repository_version');
-                $use_cache = ($this->repositoryVersion == $repository_version);
-                break;
-              default:
-                $use_cache = false;
-                break;
-            }
+            $use_cache = $this->shouldUseCache(
+              $linter->getCacheGranularity(),
+              idx($cached_result, 'repository_version'));
 
             if ($use_cache) {
               unset($paths[$key]);
@@ -260,7 +248,6 @@ abstract class ArcanistLintEngine {
 
     foreach ($linters as $linter) {
       $minimum = $this->minimumSeverity;
-      $cache_granularity = $linter->getCacheGranularity();
       foreach ($linter->getLintMessages() as $message) {
         if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) {
           continue;
@@ -268,9 +255,7 @@ abstract class ArcanistLintEngine {
         if (!$this->isRelevantMessage($message)) {
           continue;
         }
-        if ($cache_granularity == ArcanistLinter::GRANULARITY_GLOBAL) {
-          $message->setUncacheable(true);
-        }
+        $message->setGranularity($linter->getCacheGranularity());
         $result = $this->getResultForPath($message->getPath());
         $result->addMessage($message);
       }
@@ -279,11 +264,17 @@ abstract class ArcanistLintEngine {
     if ($this->cachedResults) {
       foreach ($this->cachedResults as $path => $messages) {
         $messages = idx($messages, $this->cacheVersion, array());
+        $repository_version = idx($messages, 'repository_version');
         unset($messages['stopped']);
         unset($messages['repository_version']);
         foreach ($messages as $message) {
-          $this->getResultForPath($path)->addMessage(
-            ArcanistLintMessage::newFromDictionary($message));
+          $use_cache = $this->shouldUseCache(
+            idx($message, 'granularity'),
+            $repository_version);
+          if ($use_cache) {
+            $this->getResultForPath($path)->addMessage(
+              ArcanistLintMessage::newFromDictionary($message));
+          }
         }
       }
     }
@@ -316,6 +307,18 @@ abstract class ArcanistLintEngine {
     return $this->results;
   }
 
+  private function shouldUseCache($cache_granularity, $repository_version) {
+    switch ($cache_granularity) {
+      case ArcanistLinter::GRANULARITY_FILE:
+        return true;
+      case ArcanistLinter::GRANULARITY_DIRECTORY:
+      case ArcanistLinter::GRANULARITY_REPOSITORY:
+        return ($this->repositoryVersion == $repository_version);
+      default:
+        return false;
+    }
+  }
+
   /**
    * @param dict<string path, dict<string version, list<dict message>>>
    * @return this
index 1f3cd213b5cf60f6e355dc6f8377a1621bd5aed9..6463c463960156f637d7cce6dcaed0b81239bafa 100644 (file)
@@ -195,15 +195,11 @@ EOTEXT
     $engine = newv($engine, array());
     $this->engine = $engine;
     $engine->setWorkingCopy($working_copy);
-
-    if ($use_cache) {
-      $engine->setRepositoryVersion($this->getRepositoryVersion());
-    }
-
     $engine->setMinimumSeverity(
       $this->getArgument('severity', self::DEFAULT_SEVERITY));
 
     if ($use_cache) {
+      $engine->setRepositoryVersion($this->getRepositoryVersion());
       $cache = $this->readScratchJSONFile('lint-cache.json');
       $cache = idx($cache, $this->getCacheKey(), array());
       $cache = array_intersect_key($cache, array_flip($paths));
@@ -527,7 +523,8 @@ EOTEXT
         }
         $cached_path['repository_version'] = $this->getRepositoryVersion();
         foreach ($result->getMessages() as $message) {
-          if ($message->isUncacheable()) {
+          $granularity = $message->getGranularity();
+          if ($granularity == ArcanistLinter::GRANULARITY_GLOBAL) {
             continue;
           }
           if (!$message->isPatchApplied()) {