Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/diffusion/controller/browse/DiffusionBrowseController.php b/src/applications/diffusion/controller/browse/DiffusionBrowseController.php
index 11c4abf5a1..389929a1e0 100644
--- a/src/applications/diffusion/controller/browse/DiffusionBrowseController.php
+++ b/src/applications/diffusion/controller/browse/DiffusionBrowseController.php
@@ -1,73 +1,108 @@
<?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.
*/
class DiffusionBrowseController extends DiffusionController {
private $callsign;
private $path;
private $line;
private $commit;
private $repository;
public function willProcessRequest(array $data) {
$this->callsign = $data['callsign'];
$this->path = rtrim($data['path'], '/');
$this->line = idx($data, 'line');
$this->commit = idx($data, 'commit');
}
public function processRequest() {
$repository = $this->loadRepositoryByCallsign($this->callsign);
$browse_data = DiffusionBrowseQuery::newFromRepository(
$repository,
$this->path,
$this->commit);
$results = $browse_data->loadPaths();
+ $content = array();
+
if (!$results) {
- // TODO: useful output (path does not exist / never existed), or file
- // data.
- throw new Exception("No browse results.");
+
+ switch ($browse_data->getReasonForEmptyResultSet()) {
+ case DiffusionBrowseQuery::REASON_IS_NONEXISTENT:
+ $title = 'Path Does Not Exist';
+ // TODO: Under git, this error message should be more specific. It
+ // may exist on some other branch.
+ $body = "This path does not exist anywhere.";
+ $severity = AphrontErrorView::SEVERITY_ERROR;
+ break;
+ case DiffusionBrowseQuery::REASON_IS_DELETED:
+ // TODO: Format all these commits into nice VCS-agnostic links.
+ $commit = $this->commit;
+ $deleted = $browse_data->getDeletedAtCommit();
+ $existed = $browse_data->getExistedAtCommit();
+
+ $title = 'Path Was Deleted';
+ $body = "This path does not exist at {$commit}. It was deleted in ".
+ "{$deleted} and last existed at {$existed}.";
+ $severity = AphrontErrorView::SEVERITY_WARNING;
+ break;
+ case DiffusionBrowseQuery::REASON_IS_FILE:
+ throw new Exception("TODO: implement this");
+ break;
+ default:
+ throw new Exception("Unknown failure reason!");
+ }
+
+ $error_view = new AphrontErrorView();
+ $error_view->setSeverity($severity);
+ $error_view->setTitle($title);
+ $error_view->appendChild('<p>'.$body.'</p>');
+
+ $content[] = $error_view;
+
} else {
$browse_table = new DiffusionBrowseTableView();
$browse_table->setRepository($repository);
$browse_table->setPaths($results);
$browse_table->setRoot($this->path);
$browse_table->setCommit($this->commit);
$browse_panel = new AphrontPanelView();
$browse_panel->setHeader($this->path);
$browse_panel->appendChild($browse_table);
+ $content[] = $browse_panel;
+
// TODO: Branch table
}
// TODO: Crumbs
// TODO: Side nav
return $this->buildStandardPageResponse(
- $browse_panel,
+ $content,
array(
'title' => basename($this->path),
));
}
}
diff --git a/src/applications/diffusion/controller/browse/__init__.php b/src/applications/diffusion/controller/browse/__init__.php
index 1335823c1d..faac6fe040 100644
--- a/src/applications/diffusion/controller/browse/__init__.php
+++ b/src/applications/diffusion/controller/browse/__init__.php
@@ -1,17 +1,18 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
phutil_require_module('phabricator', 'applications/diffusion/query/browse/base');
phutil_require_module('phabricator', 'applications/diffusion/view/browsetable');
+phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phutil', 'utils');
phutil_require_source('DiffusionBrowseController.php');
diff --git a/src/applications/diffusion/query/browse/base/DiffusionBrowseQuery.php b/src/applications/diffusion/query/browse/base/DiffusionBrowseQuery.php
index e94d24e2d9..0a0c4ba567 100644
--- a/src/applications/diffusion/query/browse/base/DiffusionBrowseQuery.php
+++ b/src/applications/diffusion/query/browse/base/DiffusionBrowseQuery.php
@@ -1,79 +1,90 @@
<?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.
*/
abstract class DiffusionBrowseQuery {
private $repository;
private $path;
private $commit;
protected $reason;
+ protected $existedAtCommit;
+ protected $deletedAtCommit;
- const REASON_IS_FILE = 'is-file';
- const REASON_IS_NONEXISTENT = 'nonexistent';
+ const REASON_IS_FILE = 'is-file';
+ const REASON_IS_DELETED = 'is-deleted';
+ const REASON_IS_NONEXISTENT = 'nonexistent';
final private function __construct() {
// <private>
}
final public static function newFromRepository(
PhabricatorRepository $repository,
$path = '/',
$commit = null) {
switch ($repository->getVersionControlSystem()) {
case 'git':
// TODO: Verify local-path?
$class = 'DiffusionGitBrowseQuery';
break;
default:
throw new Exception("Unsupported VCS!");
}
PhutilSymbolLoader::loadClass($class);
$query = new $class();
$query->repository = $repository;
$query->path = $path;
$query->commit = $commit;
return $query;
}
final protected function getRepository() {
return $this->repository;
}
final protected function getPath() {
return $this->path;
}
final protected function getCommit() {
return $this->commit;
}
final public function getReasonForEmptyResultSet() {
return $this->reason;
}
+ final public function getExistedAtCommit() {
+ return $this->existedAtCommit;
+ }
+
+ final public function getDeletedAtCommit() {
+ return $this->deletedAtCommit;
+ }
+
final public function loadPaths() {
return $this->executeQuery();
}
abstract protected function executeQuery();
}
diff --git a/src/applications/diffusion/query/browse/git/DiffusionGitBrowseQuery.php b/src/applications/diffusion/query/browse/git/DiffusionGitBrowseQuery.php
index de3c8455ee..c68fe6bf55 100644
--- a/src/applications/diffusion/query/browse/git/DiffusionGitBrowseQuery.php
+++ b/src/applications/diffusion/query/browse/git/DiffusionGitBrowseQuery.php
@@ -1,79 +1,95 @@
<?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.
*/
final class DiffusionGitBrowseQuery extends DiffusionBrowseQuery {
protected function executeQuery() {
$repository = $this->getRepository();
$path = $this->getPath();
$commit = nonempty($this->getCommit(), 'HEAD');
$local_path = $repository->getDetail('local-path');
$git = PhabricatorEnv::getEnvConfig('git.path');
try {
list($stdout) = execx(
"(cd %s && %s cat-file -t %s:%s)",
$local_path,
$git,
$commit,
$path);
} catch (CommandException $e) {
if (preg_match('/^fatal: Not a valid object name/', $e->getStderr())) {
+ // Grab two logs, since the first one is when the object was deleted.
+ list($stdout) = execx(
+ '(cd %s && %s log -n2 --format="%%H" %s -- %s)',
+ $local_path,
+ $git,
+ $commit,
+ $path);
+ $stdout = trim($stdout);
+ if ($stdout) {
+ $commits = explode("\n", $stdout);
+ $this->reason = self::REASON_IS_DELETED;
+ $this->deletedAtCommit = idx($commits, 0);
+ $this->existedAtCommit = idx($commits, 1);
+ return array();
+ }
+
$this->reason = self::REASON_IS_NONEXISTENT;
return array();
} else {
throw $e;
}
}
if (trim($stdout) == 'blob') {
$this->reason = self::REASON_IS_FILE;
return array();
}
list($stdout) = execx(
"(cd %s && %s ls-tree -l %s:%s)",
$local_path,
$git,
$commit,
$path);
$results = array();
foreach (explode("\n", rtrim($stdout)) as $line) {
list($mode, $type, $hash, $size, $name) = preg_split('/\s+/', $line);
if ($type == 'tree') {
$file_type = DifferentialChangeType::FILE_DIRECTORY;
} else {
$file_type = DifferentialChangeType::FILE_NORMAL;
}
$result = new DiffusionRepositoryPath();
$result->setPath($name);
$result->setHash($hash);
$result->setFileType($file_type);
$result->setFileSize($size);
$results[] = $result;
}
return $results;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Wed, Dec 3, 8:37 AM (9 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
433055
Default Alt Text
(10 KB)

Event Timeline