@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Show a better message for empty repositories and invalid branches

Summary:
Ref T1493.

- When viewing an invalid branch, show a "there is no such branch" message.
- When viewing an empty repository, show a "this repository is empty" message.

Test Plan:
- Viewed empty, bad branch, and nonempty in Git.
- Viewed empty, bad branch, and nonempty in Mercurial.
- Viewed empty and nonempty in Subversion.

Reviewers: btrahan, chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T1493

Differential Revision: https://secure.phabricator.com/D9912

+98 -14
+71 -5
src/applications/diffusion/controller/DiffusionRepositoryController.php
··· 7 7 } 8 8 9 9 public function processRequest() { 10 + $request = $this->getRequest(); 11 + $viewer = $request->getUser(); 12 + 10 13 $drequest = $this->getDiffusionRequest(); 11 14 $repository = $drequest->getRepository(); 12 15 ··· 16 19 $content[] = $crumbs; 17 20 18 21 $content[] = $this->buildPropertiesTable($drequest->getRepository()); 22 + 23 + // Before we do any work, make sure we're looking at a some content: we're 24 + // on a valid branch, and the repository is not empty. 25 + $page_has_content = false; 26 + $empty_title = null; 27 + $empty_message = null; 28 + 29 + // If this VCS supports branches, check that the selected branch actually 30 + // exists. 31 + if ($drequest->supportsBranches()) { 32 + $ref_cursor = id(new PhabricatorRepositoryRefCursorQuery()) 33 + ->setViewer($viewer) 34 + ->withRepositoryPHIDs(array($repository->getPHID())) 35 + ->withRefTypes(array(PhabricatorRepositoryRefCursor::TYPE_BRANCH)) 36 + ->withRefNames(array($drequest->getBranch())) 37 + ->executeOne(); 38 + if ($ref_cursor) { 39 + // This is a valid branch, so we necessarily have some content. 40 + $page_has_content = true; 41 + } else { 42 + $empty_title = pht('No Such Branch'); 43 + $empty_message = pht( 44 + 'There is no branch named "%s" in this repository.', 45 + $drequest->getBranch()); 46 + } 47 + } 48 + 49 + // If we didn't find any branches, check if there are any commits at all. 50 + // This can tailor the message for empty repositories. 51 + if (!$page_has_content) { 52 + $any_commit = id(new DiffusionCommitQuery()) 53 + ->setViewer($viewer) 54 + ->withRepository($repository) 55 + ->setLimit(1) 56 + ->execute(); 57 + if ($any_commit) { 58 + if (!$drequest->supportsBranches()) { 59 + $page_has_content = true; 60 + } 61 + } else { 62 + $empty_title = pht('Empty Repository'); 63 + $empty_message = pht( 64 + 'This repository does not have any commits yet.'); 65 + } 66 + } 67 + 68 + if ($page_has_content) { 69 + $content[] = $this->buildNormalContent($drequest); 70 + } else { 71 + $content[] = id(new AphrontErrorView()) 72 + ->setTitle($empty_title) 73 + ->setSeverity(AphrontErrorView::SEVERITY_WARNING) 74 + ->setErrors(array($empty_message)); 75 + } 76 + 77 + return $this->buildApplicationPage( 78 + $content, 79 + array( 80 + 'title' => $drequest->getRepository()->getName(), 81 + )); 82 + } 83 + 84 + 85 + private function buildNormalContent(DiffusionRequest $drequest) { 86 + $repository = $drequest->getRepository(); 87 + 19 88 $phids = array(); 89 + $content = array(); 20 90 21 91 try { 22 92 $history_results = $this->callConduitWithDiffusionRequest( ··· 133 203 $content[] = $panel; 134 204 } 135 205 136 - return $this->buildApplicationPage( 137 - $content, 138 - array( 139 - 'title' => $drequest->getRepository()->getName(), 140 - )); 206 + return $content; 141 207 } 142 208 143 209 private function buildPropertiesTable(PhabricatorRepository $repository) {
+1 -1
src/applications/diffusion/request/DiffusionGitRequest.php
··· 2 2 3 3 final class DiffusionGitRequest extends DiffusionRequest { 4 4 5 - protected function getSupportsBranches() { 5 + public function supportsBranches() { 6 6 return true; 7 7 } 8 8
+1 -1
src/applications/diffusion/request/DiffusionMercurialRequest.php
··· 2 2 3 3 final class DiffusionMercurialRequest extends DiffusionRequest { 4 4 5 - protected function getSupportsBranches() { 5 + public function supportsBranches() { 6 6 return true; 7 7 } 8 8
+4 -4
src/applications/diffusion/request/DiffusionRequest.php
··· 28 28 private $user; 29 29 private $branchObject = false; 30 30 31 - abstract protected function getSupportsBranches(); 31 + abstract public function supportsBranches(); 32 32 abstract protected function isStableCommit($symbol); 33 33 34 34 protected function didInitialize() { ··· 98 98 $callsign = phutil_unescape_uri_path_component(idx($data, 'callsign')); 99 99 $object = self::newFromCallsign($callsign, $request->getUser()); 100 100 101 - $use_branches = $object->getSupportsBranches(); 101 + $use_branches = $object->supportsBranches(); 102 102 $parsed = self::parseRequestBlob(idx($data, 'dblob'), $use_branches); 103 103 104 104 $object->setUser($request->getUser()); ··· 188 188 $this->initFromConduit = idx($data, 'initFromConduit', true); 189 189 190 190 $this->symbolicCommit = idx($data, 'commit'); 191 - if ($this->getSupportsBranches()) { 191 + if ($this->supportsBranches()) { 192 192 $this->branch = idx($data, 'branch'); 193 193 } 194 194 ··· 712 712 if ($this->symbolicCommit) { 713 713 $ref = $this->symbolicCommit; 714 714 } else { 715 - if ($this->getSupportsBranches()) { 715 + if ($this->supportsBranches()) { 716 716 $ref = $this->getResolvableBranchName($this->getBranch()); 717 717 } else { 718 718 $ref = 'HEAD';
+1 -1
src/applications/diffusion/request/DiffusionSvnRequest.php
··· 2 2 3 3 final class DiffusionSvnRequest extends DiffusionRequest { 4 4 5 - protected function getSupportsBranches() { 5 + public function supportsBranches() { 6 6 return false; 7 7 } 8 8
+20 -2
src/applications/repository/query/PhabricatorRepositoryRefCursorQuery.php
··· 5 5 6 6 private $repositoryPHIDs; 7 7 private $refTypes; 8 + private $refNames; 8 9 9 10 public function withRepositoryPHIDs(array $phids) { 10 11 $this->repositoryPHIDs = $phids; ··· 13 14 14 15 public function withRefTypes(array $types) { 15 16 $this->refTypes = $types; 17 + return $this; 18 + } 19 + 20 + public function withRefNames(array $names) { 21 + $this->refNames = $names; 16 22 return $this; 17 23 } 18 24 ··· 56 62 private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 57 63 $where = array(); 58 64 59 - if ($this->repositoryPHIDs) { 65 + if ($this->repositoryPHIDs !== null) { 60 66 $where[] = qsprintf( 61 67 $conn_r, 62 68 'repositoryPHID IN (%Ls)', 63 69 $this->repositoryPHIDs); 64 70 } 65 71 66 - if ($this->refTypes) { 72 + if ($this->refTypes !== null) { 67 73 $where[] = qsprintf( 68 74 $conn_r, 69 75 'refType IN (%Ls)', 70 76 $this->refTypes); 77 + } 78 + 79 + if ($this->refNames !== null) { 80 + $name_hashes = array(); 81 + foreach ($this->refNames as $name) { 82 + $name_hashes[] = PhabricatorHash::digestForIndex($name); 83 + } 84 + 85 + $where[] = qsprintf( 86 + $conn_r, 87 + 'refNameHash IN (%Ls)', 88 + $name_hashes); 71 89 } 72 90 73 91 $where[] = $this->buildPagingClause($conn_r);