mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-04-07 18:08:29 +02:00
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
This commit is contained in:
parent
a925ef9dc1
commit
4fd8b88833
1 changed files with 12 additions and 5 deletions
|
@ -199,18 +199,24 @@ EOTEXT
|
||||||
$engine->setMinimumSeverity(
|
$engine->setMinimumSeverity(
|
||||||
$this->getArgument('severity', self::DEFAULT_SEVERITY));
|
$this->getArgument('severity', self::DEFAULT_SEVERITY));
|
||||||
|
|
||||||
|
$file_hashes = array();
|
||||||
if ($use_cache) {
|
if ($use_cache) {
|
||||||
$engine->setRepositoryVersion($this->getRepositoryVersion());
|
$engine->setRepositoryVersion($this->getRepositoryVersion());
|
||||||
$cache = $this->readScratchJSONFile('lint-cache.json');
|
$cache = $this->readScratchJSONFile('lint-cache.json');
|
||||||
$cache = idx($cache, $this->getCacheKey(), array());
|
$cache = idx($cache, $this->getCacheKey(), array());
|
||||||
$cache = array_intersect_key($cache, array_flip($paths));
|
|
||||||
$cached = array();
|
$cached = array();
|
||||||
foreach ($cache as $path => $messages) {
|
|
||||||
|
foreach ($paths as $path) {
|
||||||
$abs_path = $engine->getFilePathOnDisk($path);
|
$abs_path = $engine->getFilePathOnDisk($path);
|
||||||
if (!Filesystem::pathExists($abs_path)) {
|
if (!Filesystem::pathExists($abs_path)) {
|
||||||
continue;
|
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) {
|
if ($messages !== null) {
|
||||||
$cached[$path] = $messages;
|
$cached[$path] = $messages;
|
||||||
}
|
}
|
||||||
|
@ -423,10 +429,10 @@ EOTEXT
|
||||||
|
|
||||||
if ($apply_patches && $result->isPatchable()) {
|
if ($apply_patches && $result->isPatchable()) {
|
||||||
$patcher = ArcanistLintPatcher::newFromArcanistLintResult($result);
|
$patcher = ArcanistLintPatcher::newFromArcanistLintResult($result);
|
||||||
|
$old_file = $result->getFilePathOnDisk();
|
||||||
|
|
||||||
if ($prompt_patches &&
|
if ($prompt_patches &&
|
||||||
!($result_all_autofix && !$prompt_autofix_patches)) {
|
!($result_all_autofix && !$prompt_autofix_patches)) {
|
||||||
$old_file = $result->getFilePathOnDisk();
|
|
||||||
if (!Filesystem::pathExists($old_file)) {
|
if (!Filesystem::pathExists($old_file)) {
|
||||||
$old_file = '/dev/null';
|
$old_file = '/dev/null';
|
||||||
}
|
}
|
||||||
|
@ -451,6 +457,7 @@ EOTEXT
|
||||||
|
|
||||||
$patcher->writePatchToDisk();
|
$patcher->writePatchToDisk();
|
||||||
$wrote_to_disk = true;
|
$wrote_to_disk = true;
|
||||||
|
$file_hashes[$old_file] = md5_file($old_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -526,7 +533,6 @@ EOTEXT
|
||||||
if (!Filesystem::pathExists($abs_path)) {
|
if (!Filesystem::pathExists($abs_path)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$hash = md5_file($abs_path);
|
|
||||||
$version = $result->getCacheVersion();
|
$version = $result->getCacheVersion();
|
||||||
$cached_path = array();
|
$cached_path = array();
|
||||||
if (isset($stopped[$path])) {
|
if (isset($stopped[$path])) {
|
||||||
|
@ -542,6 +548,7 @@ EOTEXT
|
||||||
$cached_path[] = $message->toDictionary();
|
$cached_path[] = $message->toDictionary();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$hash = $file_hashes[$abs_path];
|
||||||
$cached[$path] = array($hash => array($version => $cached_path));
|
$cached[$path] = array($hash => array($version => $cached_path));
|
||||||
}
|
}
|
||||||
$cache[$this->getCacheKey()] = $cached;
|
$cache[$this->getCacheKey()] = $cached;
|
||||||
|
|
Loading…
Add table
Reference in a new issue