Differential D12484 Diff 29994 src/applications/differential/controller/DifferentialChangesetViewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/controller/DifferentialChangesetViewController.php
| <?php | <?php | ||||
| final class DifferentialChangesetViewController extends DifferentialController { | final class DifferentialChangesetViewController extends DifferentialController { | ||||
| public function shouldAllowPublic() { | public function shouldAllowPublic() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $author_phid = $viewer->getPHID(); | |||||
| $rendering_reference = $request->getStr('ref'); | $rendering_reference = $request->getStr('ref'); | ||||
| $parts = explode('/', $rendering_reference); | $parts = explode('/', $rendering_reference); | ||||
| if (count($parts) == 2) { | if (count($parts) == 2) { | ||||
| list($id, $vs) = $parts; | list($id, $vs) = $parts; | ||||
| } else { | } else { | ||||
| $id = $parts[0]; | $id = $parts[0]; | ||||
| $vs = 0; | $vs = 0; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | $parser = id(new DifferentialChangesetParser()) | ||||
| ->setLeftSideCommentMapping($left_source, $left_new); | ->setLeftSideCommentMapping($left_source, $left_new); | ||||
| $parser->readParametersFromRequest($request); | $parser->readParametersFromRequest($request); | ||||
| if ($left && $right) { | if ($left && $right) { | ||||
| $parser->setOriginals($left, $right); | $parser->setOriginals($left, $right); | ||||
| } | } | ||||
| $diff = $changeset->getDiff(); | |||||
| $revision_id = $diff->getRevisionID(); | |||||
| $can_mark = false; | |||||
| $object_owner_phid = null; | |||||
| if ($revision_id) { | |||||
| $revision = id(new DifferentialRevisionQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withIDs(array($revision_id)) | |||||
| ->executeOne(); | |||||
| if ($revision) { | |||||
| $can_mark = ($revision->getAuthorPHID() == $viewer->getPHID()); | |||||
| $object_owner_phid = $revision->getAuthorPHID(); | |||||
| } | |||||
| } | |||||
| // Load both left-side and right-side inline comments. | // Load both left-side and right-side inline comments. | ||||
| if ($revision) { | |||||
| $inlines = $this->loadInlineComments( | $inlines = $this->loadInlineComments( | ||||
| array($left_source, $right_source), | $revision, | ||||
| $author_phid); | nonempty($left, $right), | ||||
| $left_new, | |||||
| $right, | |||||
| $right_new); | |||||
| } else { | |||||
| $inlines = array(); | |||||
| } | |||||
| if ($left_new) { | if ($left_new) { | ||||
| $inlines = array_merge( | $inlines = array_merge( | ||||
| $inlines, | $inlines, | ||||
| $this->buildLintInlineComments($left)); | $this->buildLintInlineComments($left)); | ||||
| } | } | ||||
| if ($right_new) { | if ($right_new) { | ||||
| Show All 20 Lines | public function handleRequest(AphrontRequest $request) { | ||||
| foreach ($inlines as $inline) { | foreach ($inlines as $inline) { | ||||
| $engine->addObject( | $engine->addObject( | ||||
| $inline, | $inline, | ||||
| PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); | PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); | ||||
| } | } | ||||
| $engine->process(); | $engine->process(); | ||||
| $diff = $changeset->getDiff(); | |||||
| $revision_id = $diff->getRevisionID(); | |||||
| $can_mark = false; | |||||
| $object_owner_phid = null; | |||||
| if ($revision_id) { | |||||
| $revision = id(new DifferentialRevisionQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withIDs(array($revision_id)) | |||||
| ->executeOne(); | |||||
| if ($revision) { | |||||
| $can_mark = ($revision->getAuthorPHID() == $viewer->getPHID()); | |||||
| $object_owner_phid = $revision->getAuthorPHID(); | |||||
| } | |||||
| } | |||||
| $parser | $parser | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setMarkupEngine($engine) | ->setMarkupEngine($engine) | ||||
| ->setShowEditAndReplyLinks(true) | ->setShowEditAndReplyLinks(true) | ||||
| ->setCanMarkDone($can_mark) | ->setCanMarkDone($can_mark) | ||||
| ->setObjectOwnerPHID($object_owner_phid) | ->setObjectOwnerPHID($object_owner_phid) | ||||
| ->setRange($range_s, $range_e) | ->setRange($range_s, $range_e) | ||||
| ->setMask($mask); | ->setMask($mask); | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | return $this->buildApplicationPage( | ||||
| $detail, | $detail, | ||||
| ), | ), | ||||
| array( | array( | ||||
| 'title' => pht('Changeset View'), | 'title' => pht('Changeset View'), | ||||
| 'device' => false, | 'device' => false, | ||||
| )); | )); | ||||
| } | } | ||||
| private function loadInlineComments(array $changeset_ids, $author_phid) { | private function loadInlineComments( | ||||
| $changeset_ids = array_unique(array_filter($changeset_ids)); | DifferentialRevision $revision, | ||||
| if (!$changeset_ids) { | DifferentialChangeset $left, | ||||
| return; | $left_new, | ||||
| } | DifferentialChangeset $right, | ||||
| $right_new) { | |||||
| return id(new DifferentialInlineCommentQuery()) | $viewer = $this->getViewer(); | ||||
| ->setViewer($this->getViewer()) | $all = array($left, $right); | ||||
| ->withChangesetIDs($changeset_ids) | |||||
| $inlines = id(new DifferentialInlineCommentQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withRevisionPHIDs(array($revision->getPHID())) | |||||
| ->execute(); | ->execute(); | ||||
| $changeset_ids = mpull($inlines, 'getChangesetID'); | |||||
| $changeset_ids = array_unique($changeset_ids); | |||||
| if ($changeset_ids) { | |||||
| $changesets = id(new DifferentialChangesetQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withIDs($changeset_ids) | |||||
| ->execute(); | |||||
| $changesets = mpull($changesets, null, 'getID'); | |||||
| } else { | |||||
| $changesets = array(); | |||||
| } | |||||
| $changesets += mpull($all, null, 'getID'); | |||||
| $id_map = array( | |||||
| $left->getID() => $left->getID(), | |||||
| $right->getID() => $right->getID(), | |||||
| ); | |||||
| $name_map = array( | |||||
| $left->getFilename() => $left->getID(), | |||||
| $right->getFilename() => $right->getID(), | |||||
| ); | |||||
| $results = array(); | |||||
| foreach ($inlines as $inline) { | |||||
| $changeset_id = $inline->getChangesetID(); | |||||
| if (isset($id_map[$changeset_id])) { | |||||
| // This inline is legitimately on one of the current changesets, so | |||||
| // we can include it in the result set unmodified. | |||||
| $results[] = $inline; | |||||
| continue; | |||||
| } | |||||
| $changeset = idx($changesets, $changeset_id); | |||||
| if (!$changeset) { | |||||
| // Just discard this inline with bogus data. | |||||
| continue; | |||||
| } | |||||
| $target_id = null; | |||||
| $filename = $changeset->getFilename(); | |||||
| if (isset($name_map[$filename])) { | |||||
| // This changeset is on a file with the same name as the current | |||||
| // changeset, so we're going to port it forward or backward. | |||||
| $target_id = $name_map[$filename]; | |||||
| } | |||||
| // If we found a changeset to port this comment to, bring it forward | |||||
| // or backward and mark it. | |||||
| if ($target_id) { | |||||
| $inline | |||||
| ->makeEphemeral(true) | |||||
| ->setChangesetID($target_id) | |||||
| ->setIsGhost(true); | |||||
| $results[] = $inline; | |||||
| } | |||||
| } | |||||
| return $results; | |||||
| } | } | ||||
| private function buildRawFileResponse( | private function buildRawFileResponse( | ||||
| DifferentialChangeset $changeset, | DifferentialChangeset $changeset, | ||||
| $is_new) { | $is_new) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| ▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines | |||||