protected $dependentMessages = array();
protected $otherLocations = array();
protected $obsolete;
- protected $uncacheable;
+ protected $granularity;
public static function newFromDictionary(array $dict) {
$message = new ArcanistLintMessage();
if (isset($dict['replacement'])) {
$message->setReplacementText($dict['replacement']);
}
+ $message->setGranularity(idx($dict, 'granularity'));
$message->setOtherLocations(idx($dict, 'locations', array()));
return $message;
}
'description' => $this->getDescription(),
'original' => $this->getOriginalText(),
'replacement' => $this->getReplacementText(),
+ 'granularity' => $this->getGranularity(),
'locations' => $this->getOtherLocations(),
);
}
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) {
}
$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).
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]);
foreach ($linters as $linter) {
$minimum = $this->minimumSeverity;
- $cache_granularity = $linter->getCacheGranularity();
foreach ($linter->getLintMessages() as $message) {
if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) {
continue;
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);
}
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));
+ }
}
}
}
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
$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));
}
$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()) {