From 4fd8b8883316b3ee1c8e8af5d1b3f3381c8d1eeb Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sun, 10 Mar 2013 18:49:02 -0700 Subject: [PATCH] Compute lint cache key before linting 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 | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/workflow/ArcanistLintWorkflow.php b/src/workflow/ArcanistLintWorkflow.php index 8865e13b..b79452e1 100644 --- a/src/workflow/ArcanistLintWorkflow.php +++ b/src/workflow/ArcanistLintWorkflow.php @@ -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;