diff --git a/src/applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php --- a/src/applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php +++ b/src/applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php @@ -17,6 +17,7 @@ protected function defineCustomParamTypes() { return array( + 'closed' => 'optional bool', 'limit' => 'optional int', 'offset' => 'optional int', 'contains' => 'optional string', @@ -97,6 +98,16 @@ } } + $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 --- a/src/applications/diffusion/controller/DiffusionRepositoryController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryController.php @@ -351,6 +351,7 @@ $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 --- a/src/applications/diffusion/request/DiffusionRequest.php +++ b/src/applications/diffusion/request/DiffusionRequest.php @@ -756,12 +756,32 @@ } 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 --- a/src/applications/diffusion/view/DiffusionBranchTableView.php +++ b/src/applications/diffusion/view/DiffusionBranchTableView.php @@ -22,6 +22,8 @@ $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 @@ '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 @@ self::linkCommit( $drequest->getRepository(), $branch->getCommitIdentifier()), + $status, $status_icon, $datetime, AphrontTableView::renderSingleDisplayLine($details), @@ -116,6 +127,7 @@ pht('History'), pht('Branch'), pht('Head'), + pht('State'), pht(''), pht('Modified'), pht('Details'), @@ -127,8 +139,16 @@ '', '', '', + '', 'wide', )); + $view->setColumnVisibility( + array( + true, + true, + true, + $can_close_branches, + )); $view->setRowClasses($rowc); return $view->render(); }