]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Compute lint cache key before linting
authorJakub Vrana <jakub@vrana.cz>
Mon, 11 Mar 2013 01:49:02 +0000 (18:49 -0700)
committerJakub Vrana <jakub@vrana.cz>
Mon, 11 Mar 2013 05:31:13 +0000 (22:31 -0700)
Summary: If user changes the file contents during linting (usually when prompted to apply a patch) then we save the old messages to the new file contents. Fix that by computing the hash before linting (or after applying patch).

Test Plan: Changed the file during linting, verified that the file hash didn't change.

Reviewers: epriestley

Reviewed By: epriestley

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

src/workflow/ArcanistLintWorkflow.php

index 8865e13b6c4eec497961b9b2d8d1c9ea847e3adc..b79452e1102131ebb31376648e4e8a4b0ceed385 100644 (file)
@@ -199,18 +199,24 @@ EOTEXT
     $engine->setMinimumSeverity(
       $this->getArgument('severity', self::DEFAULT_SEVERITY));
 
+    $file_hashes = array();
     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));
       $cached = array();
-      foreach ($cache as $path => $messages) {
+
+      foreach ($paths as $path) {
         $abs_path = $engine->getFilePathOnDisk($path);
         if (!Filesystem::pathExists($abs_path)) {
           continue;
         }
-        $messages = idx($messages, md5_file($abs_path));
+        $file_hashes[$abs_path] = md5_file($abs_path);
+
+        if (!isset($cache[$path])) {
+          continue;
+        }
+        $messages = idx($cache[$path], $file_hashes[$abs_path]);
         if ($messages !== null) {
           $cached[$path] = $messages;
         }
@@ -423,10 +429,10 @@ EOTEXT
 
       if ($apply_patches && $result->isPatchable()) {
         $patcher = ArcanistLintPatcher::newFromArcanistLintResult($result);
+        $old_file = $result->getFilePathOnDisk();
 
         if ($prompt_patches &&
             !($result_all_autofix && !$prompt_autofix_patches)) {
-          $old_file = $result->getFilePathOnDisk();
           if (!Filesystem::pathExists($old_file)) {
             $old_file = '/dev/null';
           }
@@ -451,6 +457,7 @@ EOTEXT
 
         $patcher->writePatchToDisk();
         $wrote_to_disk = true;
+        $file_hashes[$old_file] = md5_file($old_file);
       }
     }
 
@@ -526,7 +533,6 @@ EOTEXT
         if (!Filesystem::pathExists($abs_path)) {
           continue;
         }
-        $hash = md5_file($abs_path);
         $version = $result->getCacheVersion();
         $cached_path = array();
         if (isset($stopped[$path])) {
@@ -542,6 +548,7 @@ EOTEXT
             $cached_path[] = $message->toDictionary();
           }
         }
+        $hash = $file_hashes[$abs_path];
         $cached[$path] = array($hash => array($version => $cached_path));
       }
       $cache[$this->getCacheKey()] = $cached;