3 final class DiffusionBranchTableController
extends DiffusionController
{
5 public function shouldAllowPublic() {
9 public function handleRequest(AphrontRequest
$request) {
10 $response = $this->loadDiffusionContext();
15 $viewer = $this->getViewer();
16 $drequest = $this->getDiffusionRequest();
17 $repository = $drequest->getRepository();
19 $pager = id(new PHUIPagerView())
20 ->readFromRequest($request);
23 'offset' => $pager->getOffset(),
24 'limit' => $pager->getPageSize() +
1,
28 $contains = $drequest->getSymbolicCommit();
29 if (strlen($contains)) {
30 $params['contains'] = $contains;
33 $branches = $this->callConduitWithDiffusionRequest(
34 'diffusion.branchquery',
36 $branches = $pager->sliceResults($branches);
38 $branches = DiffusionRepositoryRef
::loadAllFromDictionaries($branches);
40 // If there is one page of results or fewer, sort branches so the default
41 // branch is on top and permanent branches are below it.
42 if (!$pager->getOffset() && !$pager->getHasMorePages()) {
43 $branches = $this->sortBranches($repository, $branches);
48 $content = $this->renderStatusMessage(
50 pht('This repository has no branches.'));
52 $commits = id(new DiffusionCommitQuery())
54 ->withIdentifiers(mpull($branches, 'getCommitIdentifier'))
55 ->withRepository($repository)
58 $list = id(new DiffusionBranchListView())
60 ->setBranches($branches)
61 ->setCommits($commits)
62 ->setDiffusionRequest($drequest);
64 $content = id(new PHUIObjectBoxView())
65 ->setHeaderText($repository->getName())
66 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
67 ->addClass('diffusion-mobile-view')
72 $crumbs = $this->buildCrumbs(
76 $crumbs->setBorder(true);
78 $header = id(new PHUIHeaderView())
79 ->setHeader(pht('Branches'))
80 ->setHeaderIcon('fa-code-fork');
82 if (!$repository->isSVN()) {
83 $branch_tag = $this->renderBranchTag($drequest);
84 $header->addTag($branch_tag);
87 $tabs = $this->buildTabsView('branch');
89 $view = id(new PHUITwoColumnView())
96 return $this->newPage()
100 $repository->getDisplayName(),
103 ->appendChild($view);
106 private function sortBranches(
107 PhabricatorRepository
$repository,
110 $publisher = $repository->newPublisher();
111 $default_branch = $repository->getDefaultBranch();
114 foreach ($branches as $key => $branch) {
115 $short_name = $branch->getShortName();
117 if ($short_name === $default_branch) {
123 if ($publisher->shouldPublishRef($branch)) {
124 $order_permanent = 0;
126 $order_permanent = 1;
129 $vectors[$key] = id(new PhutilSortVector())
130 ->addInt($order_default)
131 ->addInt($order_permanent)
132 ->addString($short_name);
135 $vectors = msortv($vectors, 'getSelf');
137 return array_select_keys($branches, array_keys($vectors));