Page MenuHomePhabricator

D13348.id.diff
No OneTemporary

D13348.id.diff

diff --git a/src/applications/diffusion/conduit/DiffusionFileContentQueryConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionFileContentQueryConduitAPIMethod.php
--- a/src/applications/diffusion/conduit/DiffusionFileContentQueryConduitAPIMethod.php
+++ b/src/applications/diffusion/conduit/DiffusionFileContentQueryConduitAPIMethod.php
@@ -20,6 +20,8 @@
'path' => 'required string',
'commit' => 'required string',
'needsBlame' => 'optional bool',
+ 'timeout' => 'optional int',
+ 'byteLimit' => 'optional int',
);
}
@@ -31,16 +33,30 @@
$file_query
->setViewer($request->getUser())
->setNeedsBlame($needs_blame);
+
+ $timeout = $request->getValue('timeout');
+ if ($timeout) {
+ $file_query->setTimeout($timeout);
+ }
+
+ $byte_limit = $request->getValue('byteLimit');
+ if ($byte_limit) {
+ $file_query->setByteLimit($byte_limit);
+ }
+
$file_content = $file_query->loadFileContent();
+
if ($needs_blame) {
list($text_list, $rev_list, $blame_dict) = $file_query->getBlameData();
} else {
$text_list = $rev_list = $blame_dict = array();
}
+
$file_content
->setBlameDict($blame_dict)
->setRevList($rev_list)
->setTextList($text_list);
+
return $file_content->toDictionary();
}
diff --git a/src/applications/diffusion/controller/DiffusionBrowseFileController.php b/src/applications/diffusion/controller/DiffusionBrowseFileController.php
--- a/src/applications/diffusion/controller/DiffusionBrowseFileController.php
+++ b/src/applications/diffusion/controller/DiffusionBrowseFileController.php
@@ -54,14 +54,27 @@
$needs_blame = ($show_blame && !$show_color) ||
($show_blame && $request->isAjax());
+ $params = array(
+ 'commit' => $drequest->getCommit(),
+ 'path' => $drequest->getPath(),
+ 'needsBlame' => $needs_blame,
+ );
+
+ $byte_limit = null;
+ if ($view !== 'raw') {
+ $byte_limit = PhabricatorFileStorageEngine::getChunkThreshold();
+ $time_limit = 10;
+
+ $params += array(
+ 'timeout' => $time_limit,
+ 'byteLimit' => $byte_limit,
+ );
+ }
+
$file_content = DiffusionFileContent::newFromConduit(
$this->callConduitWithDiffusionRequest(
'diffusion.filecontentquery',
- array(
- 'commit' => $drequest->getCommit(),
- 'path' => $drequest->getPath(),
- 'needsBlame' => $needs_blame,
- )));
+ $params));
$data = $file_content->getCorpus();
if ($view === 'raw') {
@@ -71,8 +84,13 @@
$this->loadLintMessages();
$this->coverage = $drequest->loadCoverage();
- $binary_uri = null;
- if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) {
+ if ($byte_limit && (strlen($data) == $byte_limit)) {
+ $corpus = $this->buildErrorCorpus(
+ pht(
+ 'This file is larger than %s byte(s), and too large to display '.
+ 'in the web UI.',
+ $byte_limit));
+ } else if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) {
$file = $this->loadFileForData($path, $data);
$file_uri = $file->getBestURI();
@@ -80,7 +98,6 @@
$corpus = $this->buildImageCorpus($file_uri);
} else {
$corpus = $this->buildBinaryCorpus($file_uri, $data);
- $binary_uri = $file_uri;
}
} else {
// Build the content of the file.
@@ -940,6 +957,21 @@
return $box;
}
+ private function buildErrorCorpus($message) {
+ $text = id(new PHUIBoxView())
+ ->addPadding(PHUI::PADDING_LARGE)
+ ->appendChild($message);
+
+ $header = id(new PHUIHeaderView())
+ ->setHeader(pht('Details'));
+
+ $box = id(new PHUIObjectBoxView())
+ ->setHeader($header)
+ ->appendChild($text);
+
+ return $box;
+ }
+
private function buildBeforeResponse($before) {
$request = $this->getRequest();
$drequest = $this->getDiffusionRequest();
diff --git a/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php b/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
--- a/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
+++ b/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
@@ -11,6 +11,26 @@
private $needsBlame;
private $fileContent;
private $viewer;
+ private $timeout;
+ private $byteLimit;
+
+ public function setTimeout($timeout) {
+ $this->timeout = $timeout;
+ return $this;
+ }
+
+ public function getTimeout() {
+ return $this->timeout;
+ }
+
+ public function setByteLimit($byte_limit) {
+ $this->byteLimit = $byte_limit;
+ return $this;
+ }
+
+ public function getByteLimit() {
+ return $this->byteLimit;
+ }
final public static function newFromDiffusionRequest(
DiffusionRequest $request) {
@@ -21,7 +41,31 @@
abstract protected function executeQueryFromFuture(Future $future);
final public function loadFileContentFromFuture(Future $future) {
- $this->fileContent = $this->executeQueryFromFuture($future);
+
+ if ($this->timeout) {
+ $future->setTimeout($this->timeout);
+ }
+
+ if ($this->getByteLimit()) {
+ $future->setStdoutSizeLimit($this->getByteLimit());
+ }
+
+ try {
+ $file_content = $this->executeQueryFromFuture($future);
+ } catch (CommandException $ex) {
+ if (!$future->getWasKilledByTimeout()) {
+ throw $ex;
+ }
+
+ $message = pht(
+ '<Attempt to load this file was terminated after %s second(s).>',
+ $this->timeout);
+
+ $file_content = new DiffusionFileContent();
+ $file_content->setCorpus($message);
+ }
+
+ $this->fileContent = $file_content;
$repository = $this->getRequest()->getRepository();
$try_encoding = $repository->getDetail('encoding');

File Metadata

Mime Type
text/plain
Expires
Thu, Jun 6, 4:12 AM (2 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6288581
Default Alt Text
D13348.id.diff (5 KB)

Event Timeline