Differential D20493 Diff 48943 src/applications/diffusion/controller/DiffusionBranchTableController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionBranchTableController.php
Show All 31 Lines | public function handleRequest(AphrontRequest $request) { | ||||
$branches = $this->callConduitWithDiffusionRequest( | $branches = $this->callConduitWithDiffusionRequest( | ||||
'diffusion.branchquery', | 'diffusion.branchquery', | ||||
$params); | $params); | ||||
$branches = $pager->sliceResults($branches); | $branches = $pager->sliceResults($branches); | ||||
$branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches); | $branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches); | ||||
// If there is one page of results or fewer, sort branches so the default | |||||
// branch is on top and permanent branches are below it. | |||||
if (!$pager->getOffset() && !$pager->getHasMorePages()) { | |||||
$branches = $this->sortBranches($repository, $branches); | |||||
} | |||||
$content = null; | $content = null; | ||||
if (!$branches) { | if (!$branches) { | ||||
$content = $this->renderStatusMessage( | $content = $this->renderStatusMessage( | ||||
pht('No Branches'), | pht('No Branches'), | ||||
pht('This repository has no branches.')); | pht('This repository has no branches.')); | ||||
} else { | } else { | ||||
$commits = id(new DiffusionCommitQuery()) | $commits = id(new DiffusionCommitQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | return $this->newPage() | ||||
array( | array( | ||||
pht('Branches'), | pht('Branches'), | ||||
$repository->getDisplayName(), | $repository->getDisplayName(), | ||||
)) | )) | ||||
->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
->appendChild($view); | ->appendChild($view); | ||||
} | } | ||||
private function sortBranches( | |||||
PhabricatorRepository $repository, | |||||
array $branches) { | |||||
$publisher = $repository->newPublisher(); | |||||
$default_branch = $repository->getDefaultBranch(); | |||||
$vectors = array(); | |||||
foreach ($branches as $key => $branch) { | |||||
$short_name = $branch->getShortName(); | |||||
if ($short_name === $default_branch) { | |||||
$order_default = 0; | |||||
} else { | |||||
$order_default = 1; | |||||
} | |||||
if ($publisher->shouldPublishRef($branch)) { | |||||
$order_permanent = 0; | |||||
} else { | |||||
$order_permanent = 1; | |||||
} | |||||
$vectors[$key] = id(new PhutilSortVector()) | |||||
->addInt($order_default) | |||||
->addInt($order_permanent) | |||||
->addString($short_name); | |||||
} | |||||
$vectors = msortv($vectors, 'getSelf'); | |||||
return array_select_keys($branches, array_keys($vectors)); | |||||
} | |||||
} | } |