Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/view/DiffusionCommitGraphView.php
| <?php | <?php | ||||
| final class DiffusionCommitGraphView | 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; | ||||
| public function setHistory(array $history) { | public function setHistory(array $history) { | ||||
| assert_instances_of($history, 'DiffusionPathChange'); | assert_instances_of($history, 'DiffusionPathChange'); | ||||
| $this->history = $history; | $this->history = $history; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getHistory() { | public function getHistory() { | ||||
| return $this->history; | return $this->history; | ||||
| } | } | ||||
| 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; | ||||
| } | } | ||||
| public function getCommits() { | public function getCommits() { | ||||
| return $this->commits; | return $this->commits; | ||||
| } | } | ||||
| public function setParents(array $parents) { | public function setParents(array $parents) { | ||||
| Show All 37 Lines | private function getRepository() { | ||||
| if (!$drequest) { | if (!$drequest) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| 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); | ||||
| $item_view = id(new PHUIObjectItemView()) | $item_view = id(new PHUIObjectItemView()) | ||||
| ->setHeader($commit_description) | ->setHeader($commit_description) | ||||
| ->setObjectName($short_hash) | ->setObjectName($short_hash) | ||||
| ->setHref($commit_link) | ->setHref($commit_link) | ||||
| ->setDisabled($is_disabled); | ->setDisabled($is_disabled); | ||||
| if ($author_view !== null) { | if ($author_view !== null) { | ||||
| $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( | ||||
| array( | array( | ||||
| $build_view, | $build_view, | ||||
| $browse_button, | $browse_button, | ||||
| )); | )); | ||||
| $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 { | |||||
| $list_view = null; | |||||
| } | |||||
| $content[] = $view; | $rows[] = array( | ||||
| $date_view, | |||||
| $list_view, | |||||
| ); | |||||
| } | |||||
| $rows[] = $content; | 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(); | ||||
| if ($graph) { | if ($graph) { | ||||
| $cells[] = phutil_tag( | $cells[] = phutil_tag( | ||||
| 'td', | 'td', | ||||
| array( | array( | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | $show_revisions = PhabricatorApplication::isClassInstalledForViewer( | ||||
| $viewer); | $viewer); | ||||
| return $show_revisions; | return $show_revisions; | ||||
| } | } | ||||
| 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, | ||||
| ); | ); | ||||
| } | } | ||||
| } | } | ||||
| return $items; | return $items; | ||||
| } | } | ||||
| Show All 15 Lines | final class DiffusionCommitGraphView | ||||
| private function getCommitURI($hash) { | private function getCommitURI($hash) { | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| if ($repository) { | if ($repository) { | ||||
| return $repository->getCommitURI($hash); | return $repository->getCommitURI($hash); | ||||
| } | } | ||||
| $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(); | ||||
| if ($repository) { | if ($repository) { | ||||
| return $repository->formatCommitName( | return $repository->formatCommitName( | ||||
| $hash, | $hash, | ||||
| $is_local = true); | $is_local = true); | ||||
| } | } | ||||
| $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; | ||||
| } | } | ||||
| if ($commit->isUnreachable()) { | if ($commit->isUnreachable()) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| Show All 30 Lines | final class DiffusionCommitGraphView | ||||
| } | } | ||||
| private function getCommit($hash) { | private function getCommit($hash) { | ||||
| $commit_map = $this->getCommitMap(); | $commit_map = $this->getCommitMap(); | ||||
| return idx($commit_map, $hash); | return idx($commit_map, $hash); | ||||
| } | } | ||||
| 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; | ||||
| } | } | ||||
| private function newBuildView($hash) { | private function newBuildView($hash) { | ||||
| $commit = $this->getCommit($hash); | $commit = $this->getCommit($hash); | ||||
| if (!$commit) { | if (!$commit) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| $buildable = $this->getBuildable($commit); | $buildable = $this->getBuildable($commit); | ||||
| if (!$buildable) { | if (!$buildable) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| return $this->renderBuildable($buildable, 'button'); | return $this->renderBuildable($buildable, 'button'); | ||||
| } | } | ||||
| private function getBuildable(PhabricatorRepositoryCommit $commit) { | private function getBuildable(PhabricatorRepositoryCommit $commit) { | ||||
| $buildable_map = $this->getBuildableMap(); | $buildable_map = $this->getBuildableMap(); | ||||
| return idx($buildable_map, $commit->getPHID()); | return idx($buildable_map, $commit->getPHID()); | ||||
| } | } | ||||
| 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; | ||||
| } | } | ||||
| return $this->buildableMap; | return $this->buildableMap; | ||||
| } | } | ||||
| private function newRevisionView($hash) { | private function newRevisionView($hash) { | ||||
| Show All 28 Lines | if ($this->revisionMap === null) { | ||||
| $this->revisionMap = $this->newRevisionMap(); | $this->revisionMap = $this->newRevisionMap(); | ||||
| } | } | ||||
| return $this->revisionMap; | return $this->revisionMap; | ||||
| } | } | ||||
| 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; | |||||
| } | |||||
| } | } | ||||