1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Move the view of merged changes to "DiffusionCommitGraphView"

Summary: Ref T13552. When viewing a merge commit, merged changes are currently shown inline. Update this view to use the new "GraphView" rendering pipeline.

Test Plan:
  - Viewed a merge commit, saw merges.
  - Viewed history, profile page, etc.

Maniphest Tasks: T13552

Differential Revision: https://secure.phabricator.com/D21413
This commit is contained in:
epriestley 2020-07-12 09:10:59 -07:00
parent cd09ba5e19
commit 7087c0439a
3 changed files with 135 additions and 67 deletions

View file

@ -811,15 +811,15 @@ final class DiffusionCommitController extends DiffusionController {
new PhutilNumber($limit))); new PhutilNumber($limit)));
} }
$history_table = id(new DiffusionHistoryTableView()) $commit_list = id(new DiffusionCommitGraphView())
->setUser($viewer) ->setViewer($viewer)
->setDiffusionRequest($drequest) ->setDiffusionRequest($drequest)
->setHistory($merges); ->setHistory($merges);
$panel = id(new PHUIObjectBoxView()) $panel = id(new PHUIObjectBoxView())
->setHeaderText(pht('Merged Changes')) ->setHeaderText(pht('Merged Changes'))
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setTable($history_table); ->setObjectList($commit_list->newObjectItemListView());
if ($caption) { if ($caption) {
$panel->setInfoView($caption); $panel->setInfoView($caption);
} }

View file

@ -35,28 +35,10 @@ final class DiffusionHistoryController extends DiffusionController {
$history = $pager->sliceResults($history); $history = $pager->sliceResults($history);
$identifiers = array();
foreach ($history as $item) {
$identifiers[] = $item->getCommitIdentifier();
}
if ($identifiers) {
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepositoryPHIDs(array($repository->getPHID()))
->withIdentifiers($identifiers)
->needCommitData(true)
->needIdentities(true)
->execute();
} else {
$commits = array();
}
$history_list = id(new DiffusionCommitGraphView()) $history_list = id(new DiffusionCommitGraphView())
->setViewer($viewer) ->setViewer($viewer)
->setDiffusionRequest($drequest) ->setDiffusionRequest($drequest)
->setHistory($history) ->setHistory($history);
->setCommits($commits);
// NOTE: If we have a path (like "src/"), many nodes in the graph are // NOTE: If we have a path (like "src/"), many nodes in the graph are
// likely to be missing (since the path wasn't touched by those commits). // likely to be missing (since the path wasn't touched by those commits).

View file

@ -4,13 +4,13 @@ final class DiffusionCommitGraphView
extends DiffusionView { extends DiffusionView {
private $history; private $history;
private $commits = array(); private $commits;
private $isHead; private $isHead;
private $isTail; private $isTail;
private $parents; private $parents;
private $filterParents; private $filterParents;
private $commitMap = array(); private $commitMap;
private $buildableMap; private $buildableMap;
private $revisionMap; private $revisionMap;
@ -27,7 +27,6 @@ final class DiffusionCommitGraphView
public function setCommits(array $commits) { public function setCommits(array $commits) {
assert_instances_of($commits, 'PhabricatorRepositoryCommit'); assert_instances_of($commits, 'PhabricatorRepositoryCommit');
$this->commits = $commits; $this->commits = $commits;
$this->commitMap = mpull($commits, null, 'getCommitIdentifier');
return $this; return $this;
} }
@ -81,40 +80,35 @@ final class DiffusionCommitGraphView
return $drequest->getRepository(); return $drequest->getRepository();
} }
public function render() { public function newObjectItemListView() {
$viewer = $this->getViewer(); $list_view = id(new PHUIObjectItemListView());
$item_views = $this->newObjectItemViews();
foreach ($item_views as $item_view) {
$list_view->addItem($item_view);
}
return $list_view;
}
private function newObjectItemViews() {
require_celerity_resource('diffusion-css'); require_celerity_resource('diffusion-css');
$show_builds = $this->shouldShowBuilds(); $show_builds = $this->shouldShowBuilds();
$show_revisions = $this->shouldShowRevisions(); $show_revisions = $this->shouldShowRevisions();
$items = $this->newHistoryItems(); $views = array();
$rows = array(); $items = $this->newHistoryItems();
$last_date = null; foreach ($items as $hash => $item) {
foreach ($items as $item) {
$content = array(); $content = array();
$item_epoch = $item['epoch'];
$item_hash = $item['hash'];
$commit = $item['commit']; $commit = $item['commit'];
$item_date = phabricator_date($item_epoch, $viewer);
if ($item_date !== $last_date) {
$last_date = $item_date;
$content[] = phutil_tag(
'div',
array(
'class' => 'diffusion-commit-graph-date-header',
),
$item_date);
}
$commit_description = $this->getCommitDescription($commit); $commit_description = $this->getCommitDescription($commit);
$commit_link = $this->getCommitURI($item_hash); $commit_link = $this->getCommitURI($hash);
$short_hash = $this->getCommitObjectName($item_hash); $short_hash = $this->getCommitObjectName($hash);
$is_disabled = $this->getCommitIsDisabled($commit); $is_disabled = $this->getCommitIsDisabled($commit);
$author_view = $this->getCommitAuthorView($commit); $author_view = $this->getCommitAuthorView($commit);
@ -129,11 +123,11 @@ final class DiffusionCommitGraphView
$item_view->addAttribute($author_view); $item_view->addAttribute($author_view);
} }
$browse_button = $this->newBrowseButton($item_hash); $browse_button = $this->newBrowseButton($hash);
$build_view = null; $build_view = null;
if ($show_builds) { if ($show_builds) {
$build_view = $this->newBuildView($item_hash); $build_view = $this->newBuildView($hash);
} }
$item_view->setSideColumn( $item_view->setSideColumn(
@ -144,22 +138,63 @@ final class DiffusionCommitGraphView
$revision_view = null; $revision_view = null;
if ($show_revisions) { if ($show_revisions) {
$revision_view = $this->newRevisionView($item_hash); $revision_view = $this->newRevisionView($hash);
} }
if ($revision_view !== null) { if ($revision_view !== null) {
$item_view->addAttribute($revision_view); $item_view->addAttribute($revision_view);
} }
$view = id(new PHUIObjectItemListView()) $views[$hash] = $item_view;
}
return $views;
}
private function newObjectItemRows() {
$viewer = $this->getViewer();
$items = $this->newHistoryItems();
$views = $this->newObjectItemViews();
$last_date = null;
$rows = array();
foreach ($items as $hash => $item) {
$item_epoch = $item['epoch'];
$item_date = phabricator_date($item_epoch, $viewer);
if ($item_date !== $last_date) {
$last_date = $item_date;
$date_view = phutil_tag(
'div',
array(
'class' => 'diffusion-commit-graph-date-header',
),
$item_date);
} else {
$date_view = null;
}
$item_view = idx($views, $hash);
if ($item_view) {
$list_view = id(new PHUIObjectItemListView())
->setFlush(true) ->setFlush(true)
->addItem($item_view); ->addItem($item_view);
} else {
$content[] = $view; $list_view = null;
$rows[] = $content;
} }
$rows[] = array(
$date_view,
$list_view,
);
}
return $rows;
}
public function render() {
$rows = $this->newObjectItemRows();
$graph = $this->newGraphView(); $graph = $this->newGraphView();
foreach ($rows as $idx => $row) { foreach ($rows as $idx => $row) {
$cells = array(); $cells = array();
@ -243,25 +278,25 @@ final class DiffusionCommitGraphView
private function newHistoryItems() { private function newHistoryItems() {
$items = array(); $items = array();
$commits = $this->getCommits();
$commit_map = mpull($commits, null, 'getCommitIdentifier');
$history = $this->getHistory(); $history = $this->getHistory();
if ($history !== null) { if ($history !== null) {
foreach ($history as $history_item) { foreach ($history as $history_item) {
$commit_hash = $history_item->getCommitIdentifier(); $commit_hash = $history_item->getCommitIdentifier();
$items[] = array( $items[$commit_hash] = array(
'epoch' => $history_item->getEpoch(), 'epoch' => $history_item->getEpoch(),
'hash' => $commit_hash, 'hash' => $commit_hash,
'commit' => idx($commit_map, $commit_hash), 'commit' => $this->getCommit($commit_hash),
); );
} }
} else { } else {
$commits = $this->getCommitMap();
foreach ($commits as $commit) { foreach ($commits as $commit) {
$items[] = array( $commit_hash = $commit->getCommitIdentifier();
$items[$commit_hash] = array(
'epoch' => $commit->getEpoch(), 'epoch' => $commit->getEpoch(),
'hash' => $commit->getCommitIdentifier(), 'hash' => $commit_hash,
'commit' => $commit, 'commit' => $commit,
); );
} }
@ -293,9 +328,13 @@ final class DiffusionCommitGraphView
} }
$commit = $this->getCommit($hash); $commit = $this->getCommit($hash);
if ($commit) {
return $commit->getURI(); return $commit->getURI();
} }
return null;
}
private function getCommitObjectName($hash) { private function getCommitObjectName($hash) {
$repository = $this->getRepository(); $repository = $this->getRepository();
@ -306,9 +345,13 @@ final class DiffusionCommitGraphView
} }
$commit = $this->getCommit($hash); $commit = $this->getCommit($hash);
if ($commit) {
return $commit->getDisplayName(); return $commit->getDisplayName();
} }
return null;
}
private function getCommitIsDisabled($commit) { private function getCommitIsDisabled($commit) {
if (!$commit) { if (!$commit) {
return true; return true;
@ -355,6 +398,11 @@ final class DiffusionCommitGraphView
} }
private function getCommitMap() { private function getCommitMap() {
if ($this->commitMap === null) {
$commit_list = $this->newCommitList();
$this->commitMap = mpull($commit_list, null, 'getCommitIdentifier');
}
return $this->commitMap; return $this->commitMap;
} }
@ -379,7 +427,7 @@ final class DiffusionCommitGraphView
private function getBuildableMap() { private function getBuildableMap() {
if ($this->buildableMap === null) { if ($this->buildableMap === null) {
$commits = $this->getCommits(); $commits = $this->getCommitMap();
$buildables = $this->loadBuildables($commits); $buildables = $this->loadBuildables($commits);
$this->buildableMap = $buildables; $this->buildableMap = $buildables;
} }
@ -424,11 +472,49 @@ final class DiffusionCommitGraphView
private function newRevisionMap() { private function newRevisionMap() {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$commits = $this->getCommits(); $commits = $this->getCommitMap();
return DiffusionCommitRevisionQuery::loadRevisionMapForCommits( return DiffusionCommitRevisionQuery::loadRevisionMapForCommits(
$viewer, $viewer,
$commits); $commits);
} }
private function newCommitList() {
$commits = $this->getCommits();
if ($commits !== null) {
return $commits;
}
$repository = $this->getRepository();
if (!$repository) {
return array();
}
$history = $this->getHistory();
if ($history === null) {
return array();
}
$identifiers = array();
foreach ($history as $item) {
$identifiers[] = $item->getCommitIdentifier();
}
if (!$identifiers) {
return array();
}
$viewer = $this->getViewer();
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepositoryPHIDs(array($repository->getPHID()))
->withIdentifiers($identifiers)
->needCommitData(true)
->needIdentities(true)
->execute();
return $commits;
}
} }