From c5ecc388a21216fd569cfa06d0e32249fce3b51c Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 3 May 2019 10:10:25 -0700 Subject: [PATCH] Make branch status more clear on Diffusion branches view Summary: See PHI1225. Ref T13277. In Diffusion, show "default", "permanent", or "not permanent" when looking at branches. For repositories with 100 or fewer branches, put default and permanent branches on top. Test Plan: {F6426814} Reviewers: amckinley Reviewed By: amckinley Subscribers: leoluk Maniphest Tasks: T13277 Differential Revision: https://secure.phabricator.com/D20493 --- .../DiffusionBranchTableController.php | 40 +++++++++++++++++++ .../view/DiffusionBranchListView.php | 13 +++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/applications/diffusion/controller/DiffusionBranchTableController.php b/src/applications/diffusion/controller/DiffusionBranchTableController.php index 65d7b8fd13..13f566a57b 100644 --- a/src/applications/diffusion/controller/DiffusionBranchTableController.php +++ b/src/applications/diffusion/controller/DiffusionBranchTableController.php @@ -37,6 +37,12 @@ final class DiffusionBranchTableController extends DiffusionController { $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; if (!$branches) { $content = $this->renderStatusMessage( @@ -97,4 +103,38 @@ final class DiffusionBranchTableController extends DiffusionController { ->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)); + } + } diff --git a/src/applications/diffusion/view/DiffusionBranchListView.php b/src/applications/diffusion/view/DiffusionBranchListView.php index 73ad87041a..c0985858f8 100644 --- a/src/applications/diffusion/view/DiffusionBranchListView.php +++ b/src/applications/diffusion/view/DiffusionBranchListView.php @@ -33,10 +33,11 @@ final class DiffusionBranchListView extends DiffusionView { Javelin::initBehavior('phabricator-tooltips'); $list = id(new PHUIObjectItemListView()) - ->setFlush(true) ->addClass('diffusion-history-list') ->addClass('diffusion-branch-list'); + $publisher = $repository->newPublisher(); + foreach ($this->branches as $branch) { $build_view = null; $button_bar = new PHUIButtonBarView(); @@ -116,8 +117,16 @@ final class DiffusionBranchListView extends DiffusionView { )); if ($branch->getShortName() == $repository->getDefaultBranch()) { - $item->setStatusIcon('fa-code-fork', pht('Default Branch')); + $item->setStatusIcon('fa-star', pht('Default Branch')); + } else { + if ($publisher->shouldPublishRef($branch)) { + $item->setStatusIcon('fa-code-fork', pht('Permanent Ref')); + } else { + $item->setStatusIcon( + 'fa-folder-open-o grey', pht('Not a Permanent Ref')); + } } + $item->addAttribute(array($datetime)); if ($can_close_branches) {