From 4faa4b451f41fccc91d0537637c4eeba9a183471 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 5 Dec 2016 18:09:51 -0800 Subject: [PATCH] When viewing a branch, preview differences from master Summary: Ref T929. When viewing a branch, show a few recent differences from the default branch (usually, "master"). Test Plan: {F2079220} Reviewers: chad Reviewed By: chad Maniphest Tasks: T929 Differential Revision: https://secure.phabricator.com/D16991 --- .../controller/DiffusionBrowseController.php | 83 +++++++++++++++++-- .../controller/DiffusionCompareController.php | 10 +-- .../view/DiffusionHistoryTableView.php | 28 ++++++- 3 files changed, 107 insertions(+), 14 deletions(-) diff --git a/src/applications/diffusion/controller/DiffusionBrowseController.php b/src/applications/diffusion/controller/DiffusionBrowseController.php index d762c60c55..f9d7b6792f 100644 --- a/src/applications/diffusion/controller/DiffusionBrowseController.php +++ b/src/applications/diffusion/controller/DiffusionBrowseController.php @@ -55,7 +55,6 @@ final class DiffusionBrowseController extends DiffusionController { } private function browseSearch() { - $drequest = $this->getDiffusionRequest(); $header = $this->buildHeaderView($drequest); @@ -77,7 +76,8 @@ final class DiffusionBrowseController extends DiffusionController { $view = id(new PHUITwoColumnView()) ->setHeader($header) - ->setFooter(array( + ->setFooter( + array( $search_form, $search_results, )); @@ -337,6 +337,7 @@ final class DiffusionBrowseController extends DiffusionController { $empty_result = null; $browse_panel = null; + $branch_panel = null; if (!$results->isValidResults()) { $empty_result = new DiffusionEmptyResultView(); $empty_result->setDiffusionRequest($drequest); @@ -376,6 +377,12 @@ final class DiffusionBrowseController extends DiffusionController { pht('Hide Search'), $search_form, '#'); + + $path = $drequest->getPath(); + $is_branch = (!strlen($path) && $repository->supportsBranchComparison()); + if ($is_branch) { + $branch_panel = $this->buildBranchTable(); + } } $open_revisions = $this->buildOpenRevisions(); @@ -394,15 +401,18 @@ final class DiffusionBrowseController extends DiffusionController { $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) - ->setMainColumn(array( - $empty_result, - $browse_panel, - )) - ->setFooter(array( + ->setMainColumn( + array( + $branch_panel, + $empty_result, + $browse_panel, + )) + ->setFooter( + array( $open_revisions, $readme, $pager_box, - )); + )); if ($details) { $view->addPropertySection(pht('Details'), $details); @@ -1951,5 +1961,62 @@ final class DiffusionBrowseController extends DiffusionController { return $file; } + private function buildBranchTable() { + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + + $branch = $drequest->getBranch(); + $default_branch = $repository->getDefaultBranch(); + + if ($branch === $default_branch) { + return null; + } + + $pager = id(new PHUIPagerView()) + ->setPageSize(10); + + try { + $results = $this->callConduitWithDiffusionRequest( + 'diffusion.historyquery', + array( + 'commit' => $branch, + 'against' => $default_branch, + 'path' => $drequest->getPath(), + 'offset' => $pager->getOffset(), + 'limit' => $pager->getPageSize() + 1, + )); + } catch (Exception $ex) { + return null; + } + + $history = DiffusionPathChange::newFromConduit($results['pathChanges']); + $history = $pager->sliceResults($history); + + if (!$history) { + return null; + } + + $history_table = id(new DiffusionHistoryTableView()) + ->setViewer($viewer) + ->setDiffusionRequest($drequest) + ->setHistory($history); + + $history_table->loadRevisions(); + + $history_table + ->setParents($results['parents']) + ->setFilterParents(true) + ->setIsHead(true) + ->setIsTail(!$pager->getHasMorePages()); + + $header = id(new PHUIHeaderView()) + ->setHeader(pht('%s vs %s', $branch, $default_branch)); + + return id(new PHUIObjectBoxView()) + ->setHeader($header) + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) + ->setTable($history_table); + } } diff --git a/src/applications/diffusion/controller/DiffusionCompareController.php b/src/applications/diffusion/controller/DiffusionCompareController.php index ab47d21910..884e740309 100644 --- a/src/applications/diffusion/controller/DiffusionCompareController.php +++ b/src/applications/diffusion/controller/DiffusionCompareController.php @@ -301,11 +301,11 @@ final class DiffusionCompareController extends DiffusionController { $history_table->loadRevisions(); - if ($history) { - $history_table->setParents($results['parents']); - $history_table->setIsHead(!$pager->getOffset()); - $history_table->setIsTail(!$pager->getHasMorePages()); - } + $history_table + ->setParents($results['parents']) + ->setFilterParents(true) + ->setIsHead(!$pager->getOffset()) + ->setIsTail(!$pager->getHasMorePages()); $header = id(new PHUIHeaderView()) ->setHeader(pht('Commits')); diff --git a/src/applications/diffusion/view/DiffusionHistoryTableView.php b/src/applications/diffusion/view/DiffusionHistoryTableView.php index 80e8aacf40..4c19e3762b 100644 --- a/src/applications/diffusion/view/DiffusionHistoryTableView.php +++ b/src/applications/diffusion/view/DiffusionHistoryTableView.php @@ -8,6 +8,7 @@ final class DiffusionHistoryTableView extends DiffusionView { private $isHead; private $isTail; private $parents; + private $filterParents; public function setHistory(array $history) { assert_instances_of($history, 'DiffusionPathChange'); @@ -66,6 +67,15 @@ final class DiffusionHistoryTableView extends DiffusionView { return $this; } + public function setFilterParents($filter_parents) { + $this->filterParents = $filter_parents; + return $this; + } + + public function getFilterParents() { + return $this->filterParents; + } + public function render() { $drequest = $this->getDiffusionRequest(); @@ -82,10 +92,26 @@ final class DiffusionHistoryTableView extends DiffusionView { $graph = null; if ($this->parents) { + $parents = $this->parents; + + // If we're filtering parents, remove relationships which point to + // commits that are not part of the visible graph. Otherwise, we get + // a big tree of nonsense when viewing release branches like "stable" + // versus "master". + if ($this->filterParents) { + foreach ($parents as $key => $nodes) { + foreach ($nodes as $nkey => $node) { + if (empty($parents[$node])) { + unset($parents[$key][$nkey]); + } + } + } + } + $graph = id(new PHUIDiffGraphView()) ->setIsHead($this->isHead) ->setIsTail($this->isTail) - ->renderGraph($this->parents); + ->renderGraph($parents); } $show_builds = PhabricatorApplication::isClassInstalledForViewer(