Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13958876
D9912.id23789.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D9912.id23789.diff
View Options
diff --git a/src/applications/diffusion/controller/DiffusionRepositoryController.php b/src/applications/diffusion/controller/DiffusionRepositoryController.php
--- a/src/applications/diffusion/controller/DiffusionRepositoryController.php
+++ b/src/applications/diffusion/controller/DiffusionRepositoryController.php
@@ -7,6 +7,9 @@
}
public function processRequest() {
+ $request = $this->getRequest();
+ $viewer = $request->getUser();
+
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
@@ -16,7 +19,74 @@
$content[] = $crumbs;
$content[] = $this->buildPropertiesTable($drequest->getRepository());
+
+ // Before we do any work, make sure we're looking at a some content: we're
+ // on a valid branch, and the repository is not empty.
+ $page_has_content = false;
+ $empty_title = null;
+ $empty_message = null;
+
+ // If this VCS supports branches, check that the selected branch actually
+ // exists.
+ if ($drequest->supportsBranches()) {
+ $ref_cursor = id(new PhabricatorRepositoryRefCursorQuery())
+ ->setViewer($viewer)
+ ->withRepositoryPHIDs(array($repository->getPHID()))
+ ->withRefTypes(array(PhabricatorRepositoryRefCursor::TYPE_BRANCH))
+ ->withRefNames(array($drequest->getBranch()))
+ ->executeOne();
+ if ($ref_cursor) {
+ // This is a valid branch, so we necessarily have some content.
+ $page_has_content = true;
+ } else {
+ $empty_title = pht('No Such Branch');
+ $empty_message = pht(
+ 'There is no branch named "%s" in this repository.',
+ $drequest->getBranch());
+ }
+ }
+
+ // If we didn't find any branches, check if there are any commits at all.
+ // This can tailor the message for empty repositories.
+ if (!$page_has_content) {
+ $any_commit = id(new DiffusionCommitQuery())
+ ->setViewer($viewer)
+ ->withRepository($repository)
+ ->setLimit(1)
+ ->execute();
+ if ($any_commit) {
+ if (!$drequest->supportsBranches()) {
+ $page_has_content = true;
+ }
+ } else {
+ $empty_title = pht('Empty Repository');
+ $empty_message = pht(
+ 'This repository does not have any commits yet.');
+ }
+ }
+
+ if ($page_has_content) {
+ $content[] = $this->buildNormalContent($drequest);
+ } else {
+ $content[] = id(new AphrontErrorView())
+ ->setTitle($empty_title)
+ ->setSeverity(AphrontErrorView::SEVERITY_WARNING)
+ ->setErrors(array($empty_message));
+ }
+
+ return $this->buildApplicationPage(
+ $content,
+ array(
+ 'title' => $drequest->getRepository()->getName(),
+ ));
+ }
+
+
+ private function buildNormalContent(DiffusionRequest $drequest) {
+ $repository = $drequest->getRepository();
+
$phids = array();
+ $content = array();
try {
$history_results = $this->callConduitWithDiffusionRequest(
@@ -133,11 +203,7 @@
$content[] = $panel;
}
- return $this->buildApplicationPage(
- $content,
- array(
- 'title' => $drequest->getRepository()->getName(),
- ));
+ return $content;
}
private function buildPropertiesTable(PhabricatorRepository $repository) {
diff --git a/src/applications/diffusion/request/DiffusionGitRequest.php b/src/applications/diffusion/request/DiffusionGitRequest.php
--- a/src/applications/diffusion/request/DiffusionGitRequest.php
+++ b/src/applications/diffusion/request/DiffusionGitRequest.php
@@ -2,7 +2,7 @@
final class DiffusionGitRequest extends DiffusionRequest {
- protected function getSupportsBranches() {
+ public function supportsBranches() {
return true;
}
diff --git a/src/applications/diffusion/request/DiffusionMercurialRequest.php b/src/applications/diffusion/request/DiffusionMercurialRequest.php
--- a/src/applications/diffusion/request/DiffusionMercurialRequest.php
+++ b/src/applications/diffusion/request/DiffusionMercurialRequest.php
@@ -2,7 +2,7 @@
final class DiffusionMercurialRequest extends DiffusionRequest {
- protected function getSupportsBranches() {
+ public function supportsBranches() {
return true;
}
diff --git a/src/applications/diffusion/request/DiffusionRequest.php b/src/applications/diffusion/request/DiffusionRequest.php
--- a/src/applications/diffusion/request/DiffusionRequest.php
+++ b/src/applications/diffusion/request/DiffusionRequest.php
@@ -28,7 +28,7 @@
private $user;
private $branchObject = false;
- abstract protected function getSupportsBranches();
+ abstract public function supportsBranches();
abstract protected function isStableCommit($symbol);
protected function didInitialize() {
@@ -98,7 +98,7 @@
$callsign = phutil_unescape_uri_path_component(idx($data, 'callsign'));
$object = self::newFromCallsign($callsign, $request->getUser());
- $use_branches = $object->getSupportsBranches();
+ $use_branches = $object->supportsBranches();
$parsed = self::parseRequestBlob(idx($data, 'dblob'), $use_branches);
$object->setUser($request->getUser());
@@ -188,7 +188,7 @@
$this->initFromConduit = idx($data, 'initFromConduit', true);
$this->symbolicCommit = idx($data, 'commit');
- if ($this->getSupportsBranches()) {
+ if ($this->supportsBranches()) {
$this->branch = idx($data, 'branch');
}
@@ -712,7 +712,7 @@
if ($this->symbolicCommit) {
$ref = $this->symbolicCommit;
} else {
- if ($this->getSupportsBranches()) {
+ if ($this->supportsBranches()) {
$ref = $this->getResolvableBranchName($this->getBranch());
} else {
$ref = 'HEAD';
diff --git a/src/applications/diffusion/request/DiffusionSvnRequest.php b/src/applications/diffusion/request/DiffusionSvnRequest.php
--- a/src/applications/diffusion/request/DiffusionSvnRequest.php
+++ b/src/applications/diffusion/request/DiffusionSvnRequest.php
@@ -2,7 +2,7 @@
final class DiffusionSvnRequest extends DiffusionRequest {
- protected function getSupportsBranches() {
+ public function supportsBranches() {
return false;
}
diff --git a/src/applications/repository/query/PhabricatorRepositoryRefCursorQuery.php b/src/applications/repository/query/PhabricatorRepositoryRefCursorQuery.php
--- a/src/applications/repository/query/PhabricatorRepositoryRefCursorQuery.php
+++ b/src/applications/repository/query/PhabricatorRepositoryRefCursorQuery.php
@@ -5,6 +5,7 @@
private $repositoryPHIDs;
private $refTypes;
+ private $refNames;
public function withRepositoryPHIDs(array $phids) {
$this->repositoryPHIDs = $phids;
@@ -16,6 +17,11 @@
return $this;
}
+ public function withRefNames(array $names) {
+ $this->refNames = $names;
+ return $this;
+ }
+
protected function loadPage() {
$table = new PhabricatorRepositoryRefCursor();
$conn_r = $table->establishConnection('r');
@@ -56,20 +62,32 @@
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
- if ($this->repositoryPHIDs) {
+ if ($this->repositoryPHIDs !== null) {
$where[] = qsprintf(
$conn_r,
'repositoryPHID IN (%Ls)',
$this->repositoryPHIDs);
}
- if ($this->refTypes) {
+ if ($this->refTypes !== null) {
$where[] = qsprintf(
$conn_r,
'refType IN (%Ls)',
$this->refTypes);
}
+ if ($this->refNames !== null) {
+ $name_hashes = array();
+ foreach ($this->refNames as $name) {
+ $name_hashes[] = PhabricatorHash::digestForIndex($name);
+ }
+
+ $where[] = qsprintf(
+ $conn_r,
+ 'refNameHash IN (%Ls)',
+ $name_hashes);
+ }
+
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Oct 15 2024, 4:49 PM (5 w, 3 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6713580
Default Alt Text
D9912.id23789.diff (7 KB)
Attached To
Mode
D9912: Show a better message for empty repositories and invalid branches
Attached
Detach File
Event Timeline
Log In to Comment