'ArcanistGitAPI' => 'repository/api/git',
'ArcanistGitHookPreReceiveWorkflow' => 'workflow/git-hook-pre-receive',
'ArcanistHelpWorkflow' => 'workflow/help',
+ 'ArcanistHookAPI' => 'repository/hookapi/base',
'ArcanistInstallCertificateWorkflow' => 'workflow/install-certificate',
'ArcanistLiberateLintEngine' => 'lint/engine/liberate',
'ArcanistLiberateWorkflow' => 'workflow/liberate',
'ArcanistRepositoryAPI' => 'repository/api/base',
'ArcanistShellCompleteWorkflow' => 'workflow/shell-complete',
'ArcanistSubversionAPI' => 'repository/api/subversion',
+ 'ArcanistSubversionHookAPI' => 'repository/hookapi/subversion',
'ArcanistSvnHookPreCommitWorkflow' => 'workflow/svn-hook-pre-commit',
'ArcanistTextLinter' => 'lint/linter/text',
'ArcanistTextLinterTestCase' => 'lint/linter/text/__tests__',
'ArcanistPyLintLinter' => 'ArcanistLinter',
'ArcanistShellCompleteWorkflow' => 'ArcanistBaseWorkflow',
'ArcanistSubversionAPI' => 'ArcanistRepositoryAPI',
+ 'ArcanistSubversionHookAPI' => 'ArcanistHookAPI',
'ArcanistSvnHookPreCommitWorkflow' => 'ArcanistBaseWorkflow',
'ArcanistTextLinter' => 'ArcanistLinter',
'ArcanistTextLinterTestCase' => 'ArcanistLinterTestCase',
private $changedLines = array();
private $commitHookMode = false;
+ private $hookAPI;
public function __construct() {
return $this;
}
- protected function loadData($path) {
+ public function setHookAPI(ArcanistHookAPI $hook_api) {
+ $this->hookAPI = $hook_api;
+ }
+
+ public function getHookAPI() {
+ return $this->hookAPI;
+ }
+
+ public function loadData($path) {
if (!isset($this->fileData[$path])) {
- $disk_path = $this->getFilePathOnDisk($path);
- $this->fileData[$path] = Filesystem::readFile($disk_path);
+ if ($this->getCommitHookMode()) {
+ $this->fileData[$path] = $this->getHookAPI()
+ ->getCurrentFileData($path);
+ } else {
+ $disk_path = $this->getFilePathOnDisk($path);
+ $this->fileData[$path] = Filesystem::readFile($disk_path);
+ }
}
return $this->fileData[$path];
}
protected function getData($path) {
if (!array_key_exists($path, $this->data)) {
- $disk_path = $this->getEngine()->getFilePathOnDisk($path);
- if ($disk_path) {
- $this->data[$path] = Filesystem::readFile($disk_path);
- } else {
- throw new Exception("Data is not provided for path '{$path}'!");
- }
+ $this->data[$path] = $this->getEngine()->loadData($path);
}
return $this->data[$path];
}
phutil_require_module('arcanist', 'lint/message');
phutil_require_module('arcanist', 'lint/severity');
-phutil_require_module('phutil', 'filesystem');
-
phutil_require_source('ArcanistLinter.php');
--- /dev/null
+<?php
+
+/*
+ * Copyright 2011 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * API while running in the context of a commit hook
+ */
+abstract class ArcanistHookAPI {
+ abstract public function getCurrentFileData($path);
+}
--- /dev/null
+<?php
+/*
+ * Copyright 2011 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * This file is automatically generated. Lint this module to rebuild it.
+ * @generated
+ */
+
+phutil_require_source('ArcanistHookAPI.php');
--- /dev/null
+<?php
+
+/*
+ * Copyright 2011 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Interfaces with Subversion while running as a commit hook.
+ */
+class ArcanistSubversionHookAPI extends ArcanistHookAPI {
+
+ protected $root;
+ protected $transaction;
+ protected $repository;
+
+ public function __construct($root, $transaction, $repository) {
+ $this->root = $root;
+ $this->transaction = $transaction;
+ $this->repository = $repository;
+ }
+
+ public function getCurrentFileData($path) {
+ list($err, $file) = exec_manual(
+ 'svnlook cat --transaction %s %s %s',
+ $this->transaction,
+ $this->repository,
+ $this->root . "/$path");
+
+ return ($err? null : $file);
+ }
+}
--- /dev/null
+<?php
+/**
+ * This file is automatically generated. Lint this module to rebuild it.
+ * @generated
+ */
+
+
+
+phutil_require_module('arcanist', 'repository/hookapi/base');
+
+phutil_require_module('phutil', 'future/exec');
+
+
+phutil_require_source('ArcanistSubversionHookAPI.php');
}
}
-
if ($failed && $resolved) {
$failed_paths = ' '.implode("\n ", $failed);
$resolved_paths = ' '.implode("\n ", array_keys($resolved));
$repository,
$config_file);
- $data = array();
- foreach ($paths as $path) {
- // TODO: This should be done in parallel.
- list($err, $filedata) = exec_manual(
- 'svnlook cat --transaction %s %s %s',
- $transaction,
- $repository,
- $path);
- $data[$path] = $err ? null : $filedata;
- }
-
$working_copy = ArcanistWorkingCopyIdentity::newFromRootAndConfigFile(
$project_root,
$config,
$config_file." (svnlook: {$transaction} {$repository})");
+ $repository_api = new ArcanistSubversionHookAPI(
+ $project_root,
+ $transaction,
+ $repository);
+
$lint_engine = $working_copy->getConfig('lint_engine');
if (!$lint_engine) {
return 0;
$engine = newv($lint_engine, array());
$engine->setWorkingCopy($working_copy);
$engine->setMinimumSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
- $engine->setPaths(array_keys($data));
- $engine->setFileData($data);
+ $engine->setPaths($paths);
$engine->setCommitHookMode(true);
+ $engine->setHookAPI($repository_api);
try {
$results = $engine->run();
phutil_require_module('arcanist', 'exception/usage');
phutil_require_module('arcanist', 'lint/renderer');
phutil_require_module('arcanist', 'lint/severity');
+phutil_require_module('arcanist', 'repository/hookapi/subversion');
phutil_require_module('arcanist', 'workflow/base');
phutil_require_module('arcanist', 'workingcopyidentity');