diff --git a/src/applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php index 1271088b1b..5fd440e4b2 100644 --- a/src/applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php +++ b/src/applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php @@ -17,6 +17,7 @@ final class DiffusionBranchQueryConduitAPIMethod protected function defineCustomParamTypes() { return array( + 'closed' => 'optional bool', 'limit' => 'optional int', 'offset' => 'optional int', 'contains' => 'optional string', @@ -97,6 +98,16 @@ final class DiffusionBranchQueryConduitAPIMethod } } + $with_closed = $request->getValue('closed'); + if ($with_closed !== null) { + foreach ($refs as $key => $ref) { + $fields = $ref->getRawFields(); + if (idx($fields, 'closed') != $with_closed) { + unset($refs[$key]); + } + } + } + // NOTE: We can't apply the offset or limit until here, because we may have // filtered untrackable branches out of the result set. diff --git a/src/applications/diffusion/controller/DiffusionRepositoryController.php b/src/applications/diffusion/controller/DiffusionRepositoryController.php index 46707f8430..7eb99b7096 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryController.php @@ -351,6 +351,7 @@ final class DiffusionRepositoryController extends DiffusionController { $branches = $this->callConduitWithDiffusionRequest( 'diffusion.branchquery', array( + 'closed' => false, 'limit' => $limit + 1, )); if (!$branches) { diff --git a/src/applications/diffusion/request/DiffusionRequest.php b/src/applications/diffusion/request/DiffusionRequest.php index 9ffd67ac07..0bd386d7ff 100644 --- a/src/applications/diffusion/request/DiffusionRequest.php +++ b/src/applications/diffusion/request/DiffusionRequest.php @@ -756,12 +756,32 @@ abstract class DiffusionRequest { } private function chooseBestRefMatch($ref, array $results) { - // TODO: Do a better job of selecting the best match. - $match = head($results); + // First, filter out less-desirable matches. + $candidates = array(); + foreach ($results as $result) { + // Exclude closed heads. + if ($result['type'] == 'branch') { + if (idx($result, 'closed')) { + continue; + } + } + + $candidates[] = $result; + } + + // If we filtered everything, undo the filtering. + if (!$candidates) { + $candidates = $results; + } + + // TODO: Do a better job of selecting the best match? + $match = head($candidates); // After choosing the best alternative, save all the alternatives so the // UI can show them to the user. - $this->refAlternatives = $results; + if (count($candidates) > 1) { + $this->refAlternatives = $candidates; + } return $match; } diff --git a/src/applications/diffusion/view/DiffusionBranchTableView.php b/src/applications/diffusion/view/DiffusionBranchTableView.php index b1e14688f1..d053d5bb33 100644 --- a/src/applications/diffusion/view/DiffusionBranchTableView.php +++ b/src/applications/diffusion/view/DiffusionBranchTableView.php @@ -22,6 +22,8 @@ final class DiffusionBranchTableView extends DiffusionView { $current_branch = $drequest->getBranch(); $repository = $drequest->getRepository(); + $can_close_branches = ($repository->isHg()); + Javelin::initBehavior('phabricator-tooltips'); $doc_href = PhabricatorEnv::getDoclink('Diffusion User Guide: Autoclose'); @@ -75,6 +77,14 @@ final class DiffusionBranchTableView extends DiffusionView { 'size' => 200, )); + $fields = $branch->getRawFields(); + $closed = idx($fields, 'closed'); + if ($closed) { + $status = pht('Closed'); + } else { + $status = pht('Open'); + } + $rows[] = array( phutil_tag( 'a', @@ -99,6 +109,7 @@ final class DiffusionBranchTableView extends DiffusionView { self::linkCommit( $drequest->getRepository(), $branch->getCommitIdentifier()), + $status, $status_icon, $datetime, AphrontTableView::renderSingleDisplayLine($details), @@ -116,6 +127,7 @@ final class DiffusionBranchTableView extends DiffusionView { pht('History'), pht('Branch'), pht('Head'), + pht('State'), pht(''), pht('Modified'), pht('Details'), @@ -127,8 +139,16 @@ final class DiffusionBranchTableView extends DiffusionView { '', '', '', + '', 'wide', )); + $view->setColumnVisibility( + array( + true, + true, + true, + $can_close_branches, + )); $view->setRowClasses($rowc); return $view->render(); }