1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

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
This commit is contained in:
epriestley 2016-12-05 18:09:51 -08:00
parent fc1adf9875
commit 4faa4b451f
3 changed files with 107 additions and 14 deletions

View file

@ -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);
}
}

View file

@ -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'));

View file

@ -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(