Path: blob/master/src/applications/diffusion/controller/DiffusionBranchTableController.php
12242 views
<?php12final class DiffusionBranchTableController extends DiffusionController {34public function shouldAllowPublic() {5return true;6}78public function handleRequest(AphrontRequest $request) {9$response = $this->loadDiffusionContext();10if ($response) {11return $response;12}1314$viewer = $this->getViewer();15$drequest = $this->getDiffusionRequest();16$repository = $drequest->getRepository();1718$pager = id(new PHUIPagerView())19->readFromRequest($request);2021$params = array(22'offset' => $pager->getOffset(),23'limit' => $pager->getPageSize() + 1,24'branch' => null,25);2627$contains = $drequest->getSymbolicCommit();28if ($contains !== null && strlen($contains)) {29$params['contains'] = $contains;30}3132$branches = $this->callConduitWithDiffusionRequest(33'diffusion.branchquery',34$params);35$branches = $pager->sliceResults($branches);3637$branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches);3839// If there is one page of results or fewer, sort branches so the default40// branch is on top and permanent branches are below it.41if (!$pager->getOffset() && !$pager->getHasMorePages()) {42$branches = $this->sortBranches($repository, $branches);43}4445$content = null;46if (!$branches) {47$content = $this->renderStatusMessage(48pht('No Branches'),49pht('This repository has no branches.'));50} else {51$commits = id(new DiffusionCommitQuery())52->setViewer($viewer)53->withIdentifiers(mpull($branches, 'getCommitIdentifier'))54->withRepository($repository)55->execute();5657$list = id(new DiffusionBranchListView())58->setUser($viewer)59->setBranches($branches)60->setCommits($commits)61->setDiffusionRequest($drequest);6263$content = id(new PHUIObjectBoxView())64->setHeaderText($repository->getName())65->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)66->addClass('diffusion-mobile-view')67->setTable($list)68->setPager($pager);69}7071$crumbs = $this->buildCrumbs(72array(73'branches' => true,74));75$crumbs->setBorder(true);7677$header = id(new PHUIHeaderView())78->setHeader(pht('Branches'))79->setHeaderIcon('fa-code-fork');8081if (!$repository->isSVN()) {82$branch_tag = $this->renderBranchTag($drequest);83$header->addTag($branch_tag);84}8586$tabs = $this->buildTabsView('branch');8788$view = id(new PHUITwoColumnView())89->setHeader($header)90->setTabs($tabs)91->setFooter(array(92$content,93));9495return $this->newPage()96->setTitle(97array(98pht('Branches'),99$repository->getDisplayName(),100))101->setCrumbs($crumbs)102->appendChild($view);103}104105private function sortBranches(106PhabricatorRepository $repository,107array $branches) {108109$publisher = $repository->newPublisher();110$default_branch = $repository->getDefaultBranch();111112$vectors = array();113foreach ($branches as $key => $branch) {114$short_name = $branch->getShortName();115116if ($short_name === $default_branch) {117$order_default = 0;118} else {119$order_default = 1;120}121122if ($publisher->shouldPublishRef($branch)) {123$order_permanent = 0;124} else {125$order_permanent = 1;126}127128$vectors[$key] = id(new PhutilSortVector())129->addInt($order_default)130->addInt($order_permanent)131->addString($short_name);132}133134$vectors = msortv($vectors, 'getSelf');135136return array_select_keys($branches, array_keys($vectors));137}138139}140141142