mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-03-30 05:58:10 +02:00
Respect granularity in reading cached lint messages
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
This commit is contained in:
parent
0795edfe1a
commit
619dd62f31
3 changed files with 34 additions and 32 deletions
|
@ -20,7 +20,7 @@ final class ArcanistLintMessage {
|
||||||
protected $dependentMessages = array();
|
protected $dependentMessages = array();
|
||||||
protected $otherLocations = array();
|
protected $otherLocations = array();
|
||||||
protected $obsolete;
|
protected $obsolete;
|
||||||
protected $uncacheable;
|
protected $granularity;
|
||||||
|
|
||||||
public static function newFromDictionary(array $dict) {
|
public static function newFromDictionary(array $dict) {
|
||||||
$message = new ArcanistLintMessage();
|
$message = new ArcanistLintMessage();
|
||||||
|
@ -38,6 +38,7 @@ final class ArcanistLintMessage {
|
||||||
if (isset($dict['replacement'])) {
|
if (isset($dict['replacement'])) {
|
||||||
$message->setReplacementText($dict['replacement']);
|
$message->setReplacementText($dict['replacement']);
|
||||||
}
|
}
|
||||||
|
$message->setGranularity(idx($dict, 'granularity'));
|
||||||
$message->setOtherLocations(idx($dict, 'locations', array()));
|
$message->setOtherLocations(idx($dict, 'locations', array()));
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
@ -53,6 +54,7 @@ final class ArcanistLintMessage {
|
||||||
'description' => $this->getDescription(),
|
'description' => $this->getDescription(),
|
||||||
'original' => $this->getOriginalText(),
|
'original' => $this->getOriginalText(),
|
||||||
'replacement' => $this->getReplacementText(),
|
'replacement' => $this->getReplacementText(),
|
||||||
|
'granularity' => $this->getGranularity(),
|
||||||
'locations' => $this->getOtherLocations(),
|
'locations' => $this->getOtherLocations(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -196,13 +198,13 @@ final class ArcanistLintMessage {
|
||||||
return $this->appliedToDisk;
|
return $this->appliedToDisk;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUncacheable($bool) {
|
public function setGranularity($granularity) {
|
||||||
$this->uncacheable = $bool;
|
$this->granularity = $granularity;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isUncacheable() {
|
public function getGranularity() {
|
||||||
return $this->uncacheable;
|
return $this->granularity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDependentMessages(array $messages) {
|
public function setDependentMessages(array $messages) {
|
||||||
|
|
|
@ -203,8 +203,6 @@ abstract class ArcanistLintEngine {
|
||||||
}
|
}
|
||||||
$paths = $linter->getPaths();
|
$paths = $linter->getPaths();
|
||||||
|
|
||||||
$cache_granularity = $linter->getCacheGranularity();
|
|
||||||
|
|
||||||
foreach ($paths as $key => $path) {
|
foreach ($paths as $key => $path) {
|
||||||
// Make sure each path has a result generated, even if it is empty
|
// Make sure each path has a result generated, even if it is empty
|
||||||
// (i.e., the file has no lint messages).
|
// (i.e., the file has no lint messages).
|
||||||
|
@ -215,19 +213,9 @@ abstract class ArcanistLintEngine {
|
||||||
if (isset($this->cachedResults[$path][$this->cacheVersion])) {
|
if (isset($this->cachedResults[$path][$this->cacheVersion])) {
|
||||||
$cached_result = $this->cachedResults[$path][$this->cacheVersion];
|
$cached_result = $this->cachedResults[$path][$this->cacheVersion];
|
||||||
|
|
||||||
switch ($cache_granularity) {
|
$use_cache = $this->shouldUseCache(
|
||||||
case ArcanistLinter::GRANULARITY_FILE:
|
$linter->getCacheGranularity(),
|
||||||
$use_cache = true;
|
idx($cached_result, 'repository_version'));
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($use_cache) {
|
if ($use_cache) {
|
||||||
unset($paths[$key]);
|
unset($paths[$key]);
|
||||||
|
@ -260,7 +248,6 @@ abstract class ArcanistLintEngine {
|
||||||
|
|
||||||
foreach ($linters as $linter) {
|
foreach ($linters as $linter) {
|
||||||
$minimum = $this->minimumSeverity;
|
$minimum = $this->minimumSeverity;
|
||||||
$cache_granularity = $linter->getCacheGranularity();
|
|
||||||
foreach ($linter->getLintMessages() as $message) {
|
foreach ($linter->getLintMessages() as $message) {
|
||||||
if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) {
|
if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -268,9 +255,7 @@ abstract class ArcanistLintEngine {
|
||||||
if (!$this->isRelevantMessage($message)) {
|
if (!$this->isRelevantMessage($message)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($cache_granularity == ArcanistLinter::GRANULARITY_GLOBAL) {
|
$message->setGranularity($linter->getCacheGranularity());
|
||||||
$message->setUncacheable(true);
|
|
||||||
}
|
|
||||||
$result = $this->getResultForPath($message->getPath());
|
$result = $this->getResultForPath($message->getPath());
|
||||||
$result->addMessage($message);
|
$result->addMessage($message);
|
||||||
}
|
}
|
||||||
|
@ -279,11 +264,17 @@ abstract class ArcanistLintEngine {
|
||||||
if ($this->cachedResults) {
|
if ($this->cachedResults) {
|
||||||
foreach ($this->cachedResults as $path => $messages) {
|
foreach ($this->cachedResults as $path => $messages) {
|
||||||
$messages = idx($messages, $this->cacheVersion, array());
|
$messages = idx($messages, $this->cacheVersion, array());
|
||||||
|
$repository_version = idx($messages, 'repository_version');
|
||||||
unset($messages['stopped']);
|
unset($messages['stopped']);
|
||||||
unset($messages['repository_version']);
|
unset($messages['repository_version']);
|
||||||
foreach ($messages as $message) {
|
foreach ($messages as $message) {
|
||||||
$this->getResultForPath($path)->addMessage(
|
$use_cache = $this->shouldUseCache(
|
||||||
ArcanistLintMessage::newFromDictionary($message));
|
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;
|
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>>>
|
* @param dict<string path, dict<string version, list<dict message>>>
|
||||||
* @return this
|
* @return this
|
||||||
|
|
|
@ -195,15 +195,11 @@ EOTEXT
|
||||||
$engine = newv($engine, array());
|
$engine = newv($engine, array());
|
||||||
$this->engine = $engine;
|
$this->engine = $engine;
|
||||||
$engine->setWorkingCopy($working_copy);
|
$engine->setWorkingCopy($working_copy);
|
||||||
|
|
||||||
if ($use_cache) {
|
|
||||||
$engine->setRepositoryVersion($this->getRepositoryVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
$engine->setMinimumSeverity(
|
$engine->setMinimumSeverity(
|
||||||
$this->getArgument('severity', self::DEFAULT_SEVERITY));
|
$this->getArgument('severity', self::DEFAULT_SEVERITY));
|
||||||
|
|
||||||
if ($use_cache) {
|
if ($use_cache) {
|
||||||
|
$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));
|
$cache = array_intersect_key($cache, array_flip($paths));
|
||||||
|
@ -527,7 +523,8 @@ EOTEXT
|
||||||
}
|
}
|
||||||
$cached_path['repository_version'] = $this->getRepositoryVersion();
|
$cached_path['repository_version'] = $this->getRepositoryVersion();
|
||||||
foreach ($result->getMessages() as $message) {
|
foreach ($result->getMessages() as $message) {
|
||||||
if ($message->isUncacheable()) {
|
$granularity = $message->getGranularity();
|
||||||
|
if ($granularity == ArcanistLinter::GRANULARITY_GLOBAL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!$message->isPatchApplied()) {
|
if (!$message->isPatchApplied()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue