Differential D19418 Diff 46452 src/applications/differential/controller/DifferentialRevisionViewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/controller/DifferentialRevisionViewController.php
| <?php | <?php | ||||
| final class DifferentialRevisionViewController extends DifferentialController { | final class DifferentialRevisionViewController | ||||
| extends DifferentialController { | |||||
| private $revisionID; | private $revisionID; | ||||
| private $veryLargeDiff; | private $changesetCount; | ||||
| public function shouldAllowPublic() { | public function shouldAllowPublic() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function isLargeDiff() { | |||||
| return ($this->getChangesetCount() > $this->getLargeDiffLimit()); | |||||
| } | |||||
| public function isVeryLargeDiff() { | public function isVeryLargeDiff() { | ||||
| return $this->veryLargeDiff; | return ($this->getChangesetCount() > $this->getVeryLargeDiffLimit()); | ||||
| } | |||||
| public function getLargeDiffLimit() { | |||||
| return 100; | |||||
| } | } | ||||
| public function getVeryLargeDiffLimit() { | public function getVeryLargeDiffLimit() { | ||||
| return 1000; | return 1000; | ||||
| } | } | ||||
| public function getChangesetCount() { | |||||
| if ($this->changesetCount === null) { | |||||
| throw new PhutilInvalidStateException('setChangesetCount'); | |||||
| } | |||||
| return $this->changesetCount; | |||||
| } | |||||
| public function setChangesetCount($count) { | |||||
| $this->changesetCount = $count; | |||||
| return $this; | |||||
| } | |||||
| public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $this->revisionID = $request->getURIData('id'); | $this->revisionID = $request->getURIData('id'); | ||||
| $viewer_is_anonymous = !$viewer->isLoggedIn(); | $viewer_is_anonymous = !$viewer->isLoggedIn(); | ||||
| $revision = id(new DifferentialRevisionQuery()) | $revision = id(new DifferentialRevisionQuery()) | ||||
| ->withIDs(array($this->revisionID)) | ->withIDs(array($this->revisionID)) | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | public function handleRequest(AphrontRequest $request) { | ||||
| } | } | ||||
| list($changesets, $vs_map, $vs_changesets, $rendering_references) = | list($changesets, $vs_map, $vs_changesets, $rendering_references) = | ||||
| $this->loadChangesetsAndVsMap( | $this->loadChangesetsAndVsMap( | ||||
| $target, | $target, | ||||
| idx($diffs, $diff_vs), | idx($diffs, $diff_vs), | ||||
| $repository); | $repository); | ||||
| if (count($rendering_references) > $this->getVeryLargeDiffLimit()) { | $this->setChangesetCount(count($rendering_references)); | ||||
| $this->veryLargeDiff = true; | |||||
| } | |||||
| if ($request->getExists('download')) { | if ($request->getExists('download')) { | ||||
| return $this->buildRawDiffResponse( | return $this->buildRawDiffResponse( | ||||
| $revision, | $revision, | ||||
| $changesets, | $changesets, | ||||
| $vs_changesets, | $vs_changesets, | ||||
| $vs_map, | $vs_map, | ||||
| $repository); | $repository); | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | foreach ($field_list->getFields() as $key => $field) { | ||||
| $object_phids[] = $phid; | $object_phids[] = $phid; | ||||
| } | } | ||||
| } | } | ||||
| $handles = $this->loadViewerHandles($object_phids); | $handles = $this->loadViewerHandles($object_phids); | ||||
| $request_uri = $request->getRequestURI(); | $request_uri = $request->getRequestURI(); | ||||
| // Revisions with more than 100 files are "large". | |||||
| // Revisions with more than 1000 files are "very large". | |||||
| $limit = 100; | |||||
| $large = $request->getStr('large'); | $large = $request->getStr('large'); | ||||
| $large_warning = | $large_warning = | ||||
| ($this->isLargeDiff()) && | |||||
| (!$this->isVeryLargeDiff()) && | (!$this->isVeryLargeDiff()) && | ||||
| (count($changesets) > $limit) && | |||||
| (!$large); | (!$large); | ||||
| if ($large_warning) { | if ($large_warning) { | ||||
| $count = count($changesets); | $count = $this->getChangesetCount(); | ||||
| $warning = new PHUIInfoView(); | $warning = new PHUIInfoView(); | ||||
| $warning->setTitle(pht('Large Diff')); | $warning->setTitle(pht('Large Diff')); | ||||
| $warning->setSeverity(PHUIInfoView::SEVERITY_WARNING); | $warning->setSeverity(PHUIInfoView::SEVERITY_WARNING); | ||||
| $warning->appendChild(hsprintf( | $warning->appendChild(hsprintf( | ||||
| '%s <strong>%s</strong>', | '%s <strong>%s</strong>', | ||||
| pht( | pht( | ||||
| 'This diff is large and affects %s files. '. | 'This diff is large and affects %s files. '. | ||||
| 'You may load each file individually or ', | 'You may load each file individually or ', | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | if ($repository && !$this->isVeryLargeDiff()) { | ||||
| $other_revisions = array(); | $other_revisions = array(); | ||||
| } | } | ||||
| $other_view = null; | $other_view = null; | ||||
| if ($other_revisions) { | if ($other_revisions) { | ||||
| $other_view = $this->renderOtherRevisions($other_revisions); | $other_view = $this->renderOtherRevisions($other_revisions); | ||||
| } | } | ||||
| $this->buildPackageMaps($changesets); | |||||
| if ($this->isVeryLargeDiff()) { | if ($this->isVeryLargeDiff()) { | ||||
| $toc_view = null; | $toc_view = null; | ||||
| // When rendering a "very large" diff, we skip computation of owners | |||||
| // that own no files because it is significantly expensive and not very | |||||
| // valuable. | |||||
| foreach ($revision->getReviewers() as $reviewer) { | |||||
| // Give each reviewer a dummy nonempty value so the UI does not render | |||||
| // the "(Owns No Changed Paths)" note. If that behavior becomes more | |||||
| // sophisticated in the future, this behavior might also need to. | |||||
| $reviewer->attachChangesets($changesets); | |||||
| } | |||||
| } else { | } else { | ||||
| $this->buildPackageMaps($changesets); | |||||
| $toc_view = $this->buildTableOfContents( | $toc_view = $this->buildTableOfContents( | ||||
| $changesets, | $changesets, | ||||
| $visible_changesets, | $visible_changesets, | ||||
| $target->loadCoverageMap($viewer)); | $target->loadCoverageMap($viewer)); | ||||
| } | |||||
| // Attach changesets to each reviewer so we can show which Owners package | // Attach changesets to each reviewer so we can show which Owners package | ||||
| // reviewers own no files. | // reviewers own no files. | ||||
| foreach ($revision->getReviewers() as $reviewer) { | foreach ($revision->getReviewers() as $reviewer) { | ||||
| $reviewer_phid = $reviewer->getReviewerPHID(); | $reviewer_phid = $reviewer->getReviewerPHID(); | ||||
| $reviewer_changesets = $this->getPackageChangesets($reviewer_phid); | $reviewer_changesets = $this->getPackageChangesets($reviewer_phid); | ||||
| $reviewer->attachChangesets($reviewer_changesets); | $reviewer->attachChangesets($reviewer_changesets); | ||||
| } | } | ||||
| } | |||||
| $tab_group = id(new PHUITabGroupView()); | $tab_group = id(new PHUITabGroupView()); | ||||
| if ($toc_view) { | if ($toc_view) { | ||||
| $tab_group->addTab( | $tab_group->addTab( | ||||
| id(new PHUITabView()) | id(new PHUITabView()) | ||||
| ->setName(pht('Files')) | ->setName(pht('Files')) | ||||
| ->setKey('files') | ->setKey('files') | ||||
| ▲ Show 20 Lines • Show All 828 Lines • Show Last 20 Lines | |||||