1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 16:22:42 +01:00

Allow setting lint cache granularity

Summary:
We can add `GRANULARITY_DIRECTORY` and `GRANULARITY_REPOSITORY` later.
Repository granularity may use current commit + changes.
Directory would need to use hashes of all files in dir which would be quite expensive.

Test Plan:
  $ echo '<?php class A extends B {}' > A.php
  $ arc lint --cache 1
  $ arc lint --cache 1
  $ echo '<?php class B {}' > B.php
  $ arc lint --cache 1
  $ arc lint --cache 1
  $ rm B.php
  $ arc lint --cache 1
  $ arc lint --cache 1

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4021
This commit is contained in:
vrana 2012-11-21 18:38:24 -08:00
parent 0d1d04e434
commit e8eacb6ae3
5 changed files with 46 additions and 4 deletions

View file

@ -19,6 +19,7 @@ final class ArcanistLintMessage {
protected $appliedToDisk;
protected $dependentMessages = array();
protected $obsolete;
protected $uncacheable;
public static function newFromDictionary(array $dict) {
$message = new ArcanistLintMessage();
@ -179,6 +180,15 @@ final class ArcanistLintMessage {
return $this->appliedToDisk;
}
public function setUncacheable($bool) {
$this->uncacheable = $bool;
return $this;
}
public function isUncacheable() {
return $this->uncacheable;
}
public function setDependentMessages(array $messages) {
assert_instances_of($messages, 'ArcanistLintMessage');
$this->dependentMessages = $messages;

View file

@ -198,6 +198,8 @@ abstract class ArcanistLintEngine {
}
$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).
@ -205,11 +207,12 @@ abstract class ArcanistLintEngine {
if (isset($stopped[$path])) {
unset($paths[$key]);
}
// TODO: Some linters work with the whole directory.
if (isset($this->cachedResults[$path][$this->cacheVersion])) {
if ($cache_granularity == ArcanistLinter::GRANULARITY_FILE) {
unset($paths[$key]);
}
}
}
$paths = array_values($paths);
if ($paths) {
@ -231,6 +234,9 @@ abstract class ArcanistLintEngine {
if (!$this->isRelevantMessage($message)) {
continue;
}
if ($cache_granularity != ArcanistLinter::GRANULARITY_FILE) {
$message->setUncacheable(true);
}
$result = $this->getResultForPath($message->getPath());
$result->addMessage($message);
}

View file

@ -8,6 +8,11 @@
*/
abstract class ArcanistLinter {
const GRANULARITY_FILE = 1;
const GRANULARITY_DIRECTORY = 2;
const GRANULARITY_REPOSITORY = 3;
const GRANULARITY_GLOBAL = 4;
protected $paths = array();
protected $data = array();
protected $engine;
@ -211,4 +216,8 @@ abstract class ArcanistLinter {
return array();
}
public function getCacheGranularity() {
return self::GRANULARITY_FILE;
}
}

View file

@ -171,4 +171,9 @@ final class ArcanistPhutilLibraryLinter extends ArcanistLinter {
public function lintPath($path) {
return;
}
public function getCacheGranularity() {
return self::GRANULARITY_GLOBAL;
}
}

View file

@ -192,9 +192,14 @@ EOTEXT
if ($this->getArgument('cache')) {
$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) {
$messages = idx($messages, md5_file($engine->getFilePathOnDisk($path)));
$abs_path = $engine->getFilePathOnDisk($path);
if (!Filesystem::pathExists($abs_path)) {
continue;
}
$messages = idx($messages, md5_file($abs_path));
if ($messages !== null) {
$cached[$path] = $messages;
}
@ -400,10 +405,17 @@ EOTEXT
unset($cached[$path]);
continue;
}
$hash = md5_file($engine->getFilePathOnDisk($path));
$abs_path = $engine->getFilePathOnDisk($path);
if (!Filesystem::pathExists($abs_path)) {
continue;
}
$hash = md5_file($abs_path);
$version = $result->getCacheVersion();
$cached[$path] = array($hash => array($version => array()));
foreach ($result->getMessages() as $message) {
if ($message->isUncacheable()) {
continue;
}
if (!$message->isPatchApplied()) {
$cached[$path][$hash][$version][] = $message->toDictionary();
}