3 final class DiffusionCommitController
extends DiffusionController
{
5 const CHANGES_LIMIT
= 100;
7 private $commitParents;
10 private $commitErrors;
11 private $commitExists;
13 public function shouldAllowPublic() {
17 public function handleRequest(AphrontRequest
$request) {
18 $response = $this->loadDiffusionContext();
23 $drequest = $this->getDiffusionRequest();
24 $viewer = $request->getUser();
25 $repository = $drequest->getRepository();
26 $commit_identifier = $drequest->getCommit();
28 // If this page is being accessed via "/source/xyz/commit/...", redirect
29 // to the canonical URI.
30 $has_callsign = strlen($request->getURIData('repositoryCallsign'));
31 $has_id = strlen($request->getURIData('repositoryID'));
32 if (!$has_callsign && !$has_id) {
33 $canonical_uri = $repository->getCommitURI($commit_identifier);
34 return id(new AphrontRedirectResponse())
35 ->setURI($canonical_uri);
38 if ($request->getStr('diff')) {
39 return $this->buildRawDiffResponse($drequest);
42 $commits = id(new DiffusionCommitQuery())
44 ->withRepository($repository)
45 ->withIdentifiers(array($commit_identifier))
46 ->needCommitData(true)
47 ->needAuditRequests(true)
48 ->needAuditAuthority(array($viewer))
50 ->needIdentities(true)
53 $multiple_results = count($commits) > 1;
55 $crumbs = $this->buildCrumbs(array(
56 'commit' => !$multiple_results,
58 $crumbs->setBorder(true);
61 if (!$this->getCommitExists()) {
62 return new Aphront404Response();
65 $error = id(new PHUIInfoView())
66 ->setTitle(pht('Commit Still Parsing'))
69 'Failed to load the commit because the commit has not been '.
72 $title = pht('Commit Still Parsing');
74 return $this->newPage()
77 ->appendChild($error);
78 } else if ($multiple_results) {
82 'The identifier %s is ambiguous and matches more than one commit.',
88 $error = id(new PHUIInfoView())
89 ->setTitle(pht('Ambiguous Commit'))
90 ->setSeverity(PHUIInfoView
::SEVERITY_WARNING
)
91 ->appendChild($warning_message);
93 $list = id(new DiffusionCommitGraphView())
95 ->setCommits($commits);
97 $crumbs->addTextCrumb(pht('Ambiguous Commit'));
99 $matched_commits = id(new PHUITwoColumnView())
105 return $this->newPage()
106 ->setTitle(pht('Ambiguous Commit'))
108 ->appendChild($matched_commits);
110 $commit = head($commits);
113 $audit_requests = $commit->getAudits();
115 $commit_data = $commit->getCommitData();
116 $is_foreign = $commit_data->getCommitDetail('foreign-svn-stub');
118 $unpublished_panel = null;
122 if ($commit->isImported()) {
123 $change_query = DiffusionPathChangeQuery
::newFromDiffusionRequest(
125 $change_query->setLimit($hard_limit +
1);
126 $changes = $change_query->loadChanges();
131 $was_limited = (count($changes) > $hard_limit);
133 $changes = array_slice($changes, 0, $hard_limit);
136 $count = count($changes);
138 $is_unreadable = false;
140 if (!$count ||
$commit->isUnreachable()) {
141 $hint = id(new DiffusionCommitHintQuery())
143 ->withRepositoryPHIDs(array($repository->getPHID()))
144 ->withOldCommitIdentifiers(array($commit->getCommitIdentifier()))
147 $is_unreadable = $hint->isUnreadable();
152 $subpath = $commit_data->getCommitDetail('svn-subpath');
154 $error_panel = new PHUIInfoView();
155 $error_panel->setTitle(pht('Commit Not Tracked'));
156 $error_panel->setSeverity(PHUIInfoView
::SEVERITY_WARNING
);
157 $error_panel->appendChild(
159 "This Diffusion repository is configured to track only one ".
160 "subdirectory of the entire Subversion repository, and this commit ".
161 "didn't affect the tracked subdirectory ('%s'), so no ".
162 "information is available.",
165 $engine = PhabricatorMarkupEngine
::newDifferentialMarkupEngine();
166 $engine->setConfig('viewer', $viewer);
168 $commit_tag = $this->renderCommitHashTag($drequest);
169 $header = id(new PHUIHeaderView())
170 ->setHeader(nonempty($commit->getSummary(), pht('Commit Detail')))
171 ->setHeaderIcon('fa-code-fork')
172 ->addTag($commit_tag);
174 if (!$commit->isAuditStatusNoAudit()) {
175 $status = $commit->getAuditStatusObject();
177 $icon = $status->getIcon();
178 $color = $status->getColor();
179 $status = $status->getName();
181 $header->setStatus($icon, $color, $status);
184 $curtain = $this->buildCurtain($commit, $repository);
185 $details = $this->buildPropertyListView(
190 $message = $commit_data->getCommitMessage();
192 $revision = $commit->getCommitIdentifier();
193 $message = $this->linkBugtraq($message);
194 $message = $engine->markupText($message);
196 $detail_list = new PHUIPropertyListView();
197 $detail_list->addTextContent(
201 'class' => 'diffusion-commit-message phabricator-remarkup',
205 if ($commit->isUnreachable()) {
206 $did_rewrite = false;
208 if ($hint->isRewritten()) {
209 $rewritten = id(new DiffusionCommitQuery())
211 ->withRepository($repository)
212 ->withIdentifiers(array($hint->getNewCommitIdentifier()))
216 $rewritten_uri = $rewritten->getURI();
217 $rewritten_name = $rewritten->getLocalName();
219 $rewritten_link = phutil_tag(
222 'href' => $rewritten_uri,
226 $this->commitErrors
[] = pht(
227 'This commit was rewritten after it was published, which '.
228 'changed the commit hash. This old version of the commit is '.
229 'no longer reachable from any branch, tag or ref. The new '.
230 'version of this commit is %s.',
237 $this->commitErrors
[] = pht(
238 'This commit has been deleted in the repository: it is no longer '.
239 'reachable from any branch, tag, or ref.');
242 if (!$commit->isPermanentCommit()) {
243 $nonpermanent_tag = id(new PHUITagView())
244 ->setType(PHUITagView
::TYPE_SHADE
)
245 ->setName(pht('Unpublished'))
246 ->setColor(PHUITagView
::COLOR_ORANGE
);
248 $header->addTag($nonpermanent_tag);
250 $holds = $commit_data->newPublisherHoldReasons();
253 foreach ($holds as $hold) {
255 phutil_tag('strong', array(), pht('%s:', $hold->getName())),
262 $reasons[] = pht('No further details are available.');
265 $doc_href = PhabricatorEnv
::getDoclink(
266 'Diffusion User Guide: Permanent Refs');
267 $doc_link = phutil_tag(
271 'target' => '_blank',
276 pht('Unpublished Commit'),
281 $unpublished_panel = id(new PHUIInfoView())
283 ->setErrors($reasons)
284 ->setSeverity(PHUIInfoView
::SEVERITY_WARNING
);
288 if ($this->getCommitErrors()) {
289 $error_panel = id(new PHUIInfoView())
290 ->appendChild($this->getCommitErrors())
291 ->setSeverity(PHUIInfoView
::SEVERITY_WARNING
);
295 $timeline = $this->buildComments($commit);
296 $merge_table = $this->buildMergesTable($commit);
298 $show_changesets = false;
301 $change_table = null;
302 if ($is_unreadable) {
303 $info_panel = $this->renderStatusMessage(
304 pht('Unreadable Commit'),
306 'This commit has been marked as unreadable by an administrator. '.
307 'It may have been corrupted or created improperly by an external '.
309 } else if ($is_foreign) {
310 // Don't render anything else.
311 } else if (!$commit->isImported()) {
312 $info_panel = $this->renderStatusMessage(
313 pht('Still Importing...'),
315 'This commit is still importing. Changes will be visible once '.
316 'the import finishes.'));
317 } else if (!count($changes)) {
318 $info_panel = $this->renderStatusMessage(
321 'This commit is empty and does not affect any paths.'));
322 } else if ($was_limited) {
323 $info_panel = $this->renderStatusMessage(
324 pht('Very Large Commit'),
326 'This commit is very large, and affects more than %d files. '.
327 'Changes are not shown.',
329 } else if (!$this->getCommitExists()) {
330 $info_panel = $this->renderStatusMessage(
331 pht('Commit No Longer Exists'),
332 pht('This commit no longer exists in the repository.'));
334 $show_changesets = true;
336 // The user has clicked "Show All Changes", and we should show all the
337 // changes inline even if there are more than the soft limit.
338 $show_all_details = $request->getBool('show_all');
340 $change_header = id(new PHUIHeaderView())
341 ->setHeader(pht('Changes (%s)', new PhutilNumber($count)));
343 $warning_view = null;
344 if ($count > self
::CHANGES_LIMIT
&& !$show_all_details) {
345 $button = id(new PHUIButtonView())
346 ->setText(pht('Show All Changes'))
347 ->setHref('?show_all=true')
349 ->setIcon('fa-files-o');
351 $warning_view = id(new PHUIInfoView())
352 ->setSeverity(PHUIInfoView
::SEVERITY_WARNING
)
353 ->setTitle(pht('Very Large Commit'))
355 pht('This commit is very large. Load each file individually.'));
357 $change_header->addActionLink($button);
360 $changesets = DiffusionPathChange
::convertToDifferentialChangesets(
364 // TODO: This table and panel shouldn't really be separate, but we need
365 // to clean up the "Load All Files" interaction first.
366 $change_table = $this->buildTableOfContents(
371 $vcs = $repository->getVersionControlSystem();
373 case PhabricatorRepositoryType
::REPOSITORY_TYPE_SVN
:
374 $vcs_supports_directory_changes = true;
376 case PhabricatorRepositoryType
::REPOSITORY_TYPE_GIT
:
377 case PhabricatorRepositoryType
::REPOSITORY_TYPE_MERCURIAL
:
378 $vcs_supports_directory_changes = false;
381 throw new Exception(pht('Unknown VCS.'));
384 $references = array();
385 foreach ($changesets as $key => $changeset) {
386 $file_type = $changeset->getFileType();
387 if ($file_type == DifferentialChangeType
::FILE_DIRECTORY
) {
388 if (!$vcs_supports_directory_changes) {
389 unset($changesets[$key]);
394 $references[$key] = $drequest->generateURI(
396 'action' => 'rendering-ref',
397 'path' => $changeset->getFilename(),
401 // TODO: Some parts of the views still rely on properties of the
402 // DifferentialChangeset. Make the objects ephemeral to make sure we don't
403 // accidentally save them, and then set their ID to the appropriate ID for
404 // this application (the path IDs).
405 $path_ids = array_flip(mpull($changes, 'getPath'));
406 foreach ($changesets as $changeset) {
407 $changeset->makeEphemeral();
408 $changeset->setID($path_ids[$changeset->getFilename()]);
411 if ($count <= self
::CHANGES_LIMIT ||
$show_all_details) {
412 $visible_changesets = $changesets;
414 $visible_changesets = array();
416 $inlines = id(new DiffusionDiffInlineCommentQuery())
418 ->withCommitPHIDs(array($commit->getPHID()))
419 ->withPublishedComments(true)
420 ->withPublishableComments(true)
422 $inlines = mpull($inlines, 'newInlineCommentObject');
424 $path_ids = mpull($inlines, null, 'getPathID');
425 foreach ($changesets as $key => $changeset) {
426 if (array_key_exists($changeset->getID(), $path_ids)) {
427 $visible_changesets[$key] = $changeset;
432 $change_list_title = $commit->getDisplayName();
434 $change_list = new DifferentialChangesetListView();
435 $change_list->setTitle($change_list_title);
436 $change_list->setChangesets($changesets);
437 $change_list->setVisibleChangesets($visible_changesets);
438 $change_list->setRenderingReferences($references);
439 $change_list->setRenderURI($repository->getPathURI('diff/'));
440 $change_list->setRepository($repository);
441 $change_list->setUser($viewer);
442 $change_list->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
);
444 // TODO: Try to setBranch() to something reasonable here?
446 $change_list->setStandaloneURI(
447 $repository->getPathURI('diff/'));
449 $change_list->setRawFileURIs(
450 // TODO: Implement this, somewhat tricky if there's an octopus merge
453 $repository->getPathURI('diff/?view=r'));
455 $change_list->setInlineCommentControllerURI(
456 '/diffusion/inline/edit/'.phutil_escape_uri($commit->getPHID()).'/');
460 $add_comment = $this->renderAddCommentPanel(
464 $filetree = id(new DifferentialFileTreeEngine())
466 ->setDisabled(!$show_changesets);
468 if ($show_changesets) {
469 $filetree->setChangesets($changesets);
472 $description_box = id(new PHUIObjectBoxView())
473 ->setHeaderText(pht('Description'))
474 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
475 ->appendChild($detail_list);
477 $detail_box = id(new PHUIObjectBoxView())
478 ->setHeaderText(pht('Details'))
479 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
480 ->appendChild($details);
482 $view = id(new PHUITwoColumnView())
484 ->setCurtain($curtain)
502 $main_content = array(
507 $main_content = $filetree->newView($main_content);
508 if (!$filetree->getDisabled()) {
509 $change_list->setFormationView($main_content);
512 $page = $this->newPage()
513 ->setTitle($commit->getDisplayName())
514 ->setPageObjectPHIDS(array($commit->getPHID()))
515 ->appendChild($main_content);
521 private function buildPropertyListView(
522 PhabricatorRepositoryCommit
$commit,
523 PhabricatorRepositoryCommitData
$data,
524 array $audit_requests) {
526 $viewer = $this->getViewer();
527 $commit_phid = $commit->getPHID();
528 $drequest = $this->getDiffusionRequest();
529 $repository = $drequest->getRepository();
531 $view = id(new PHUIPropertyListView())
532 ->setUser($this->getRequest()->getUser())
533 ->setObject($commit);
535 $edge_query = id(new PhabricatorEdgeQuery())
536 ->withSourcePHIDs(array($commit_phid))
537 ->withEdgeTypes(array(
538 DiffusionCommitHasTaskEdgeType
::EDGECONST
,
539 DiffusionCommitHasRevisionEdgeType
::EDGECONST
,
540 DiffusionCommitRevertsCommitEdgeType
::EDGECONST
,
541 DiffusionCommitRevertedByCommitEdgeType
::EDGECONST
,
544 $edges = $edge_query->execute();
546 $task_phids = array_keys(
547 $edges[$commit_phid][DiffusionCommitHasTaskEdgeType
::EDGECONST
]);
548 $revision_phid = key(
549 $edges[$commit_phid][DiffusionCommitHasRevisionEdgeType
::EDGECONST
]);
551 $reverts_phids = array_keys(
552 $edges[$commit_phid][DiffusionCommitRevertsCommitEdgeType
::EDGECONST
]);
553 $reverted_by_phids = array_keys(
554 $edges[$commit_phid][DiffusionCommitRevertedByCommitEdgeType
::EDGECONST
]);
556 $phids = $edge_query->getDestinationPHIDs(array($commit_phid));
559 if ($data->getCommitDetail('reviewerPHID')) {
560 $phids[] = $data->getCommitDetail('reviewerPHID');
563 $phids[] = $commit->getCommitterDisplayPHID();
564 $phids[] = $commit->getAuthorDisplayPHID();
566 // NOTE: We should never normally have more than a single push log, but
567 // it can occur naturally if a commit is pushed, then the branch it was
568 // on is deleted, then the commit is pushed again (or through other similar
569 // chains of events). This should be rare, but does not indicate a bug
572 // NOTE: We never query push logs in SVN because the committer is always
573 // the pusher and the commit time is always the push time; the push log
574 // is redundant and we save a query by skipping it.
576 $push_logs = array();
577 if ($repository->isHosted() && !$repository->isSVN()) {
578 $push_logs = id(new PhabricatorRepositoryPushLogQuery())
580 ->withRepositoryPHIDs(array($repository->getPHID()))
581 ->withNewRefs(array($commit->getCommitIdentifier()))
582 ->withRefTypes(array(PhabricatorRepositoryPushLog
::REFTYPE_COMMIT
))
584 foreach ($push_logs as $log) {
585 $phids[] = $log->getPusherPHID();
591 $handles = $this->loadViewerHandles($phids);
596 if ($audit_requests) {
597 $user_requests = array();
598 $other_requests = array();
600 foreach ($audit_requests as $audit_request) {
601 if ($audit_request->isUser()) {
602 $user_requests[] = $audit_request;
604 $other_requests[] = $audit_request;
608 if ($user_requests) {
611 $this->renderAuditStatusView($commit, $user_requests));
614 if ($other_requests) {
616 pht('Group Auditors'),
617 $this->renderAuditStatusView($commit, $other_requests));
621 $provenance_list = new PHUIStatusListView();
623 $author_view = $commit->newCommitAuthorView($viewer);
625 $author_date = $data->getAuthorEpoch();
626 $author_date = phabricator_datetime($author_date, $viewer);
628 $provenance_list->addItem(
629 id(new PHUIStatusItemView())
630 ->setTarget($author_view)
631 ->setNote(pht('Authored on %s', $author_date)));
634 if (!$commit->isAuthorSameAsCommitter()) {
635 $committer_view = $commit->newCommitCommitterView($viewer);
636 if ($committer_view) {
637 $committer_date = $commit->getEpoch();
638 $committer_date = phabricator_datetime($committer_date, $viewer);
640 $provenance_list->addItem(
641 id(new PHUIStatusItemView())
642 ->setTarget($committer_view)
643 ->setNote(pht('Committed on %s', $committer_date)));
648 $pushed_list = new PHUIStatusListView();
650 foreach ($push_logs as $push_log) {
651 $pusher_date = $push_log->getEpoch();
652 $pusher_date = phabricator_datetime($pusher_date, $viewer);
654 $pusher_view = $handles[$push_log->getPusherPHID()]->renderLink();
656 $provenance_list->addItem(
657 id(new PHUIStatusItemView())
658 ->setTarget($pusher_view)
659 ->setNote(pht('Pushed on %s', $pusher_date)));
663 $view->addProperty(pht('Provenance'), $provenance_list);
665 $reviewer_phid = $data->getCommitDetail('reviewerPHID');
666 if ($reviewer_phid) {
669 $handles[$reviewer_phid]->renderLink());
672 if ($revision_phid) {
674 pht('Differential Revision'),
675 $handles[$revision_phid]->renderLink());
678 $parents = $this->getCommitParents();
682 $viewer->renderHandleList(mpull($parents, 'getPHID')));
685 if ($this->getCommitExists()) {
691 'id' => 'commit-branches',
700 'id' => 'commit-tags',
704 $identifier = $commit->getCommitIdentifier();
705 $root = $repository->getPathURI("commit/{$identifier}");
706 Javelin
::initBehavior(
707 'diffusion-commit-branches',
709 $root.'/branches/' => 'commit-branches',
710 $root.'/tags/' => 'commit-tags',
714 $refs = $this->getCommitRefs();
716 $ref_links = array();
717 foreach ($refs as $ref_data) {
718 $ref_links[] = phutil_tag(
721 'href' => $ref_data['href'],
727 phutil_implode_html(', ', $ref_links));
730 if ($reverts_phids) {
733 $viewer->renderHandleList($reverts_phids));
736 if ($reverted_by_phids) {
739 $viewer->renderHandleList($reverted_by_phids));
743 $task_list = array();
744 foreach ($task_phids as $phid) {
745 $task_list[] = $handles[$phid]->renderLink();
747 $task_list = phutil_implode_html(phutil_tag('br'), $task_list);
756 private function buildComments(PhabricatorRepositoryCommit
$commit) {
757 $timeline = $this->buildTransactionTimeline(
759 new PhabricatorAuditTransactionQuery());
761 $timeline->setQuoteRef($commit->getMonogram());
766 private function renderAddCommentPanel(
767 PhabricatorRepositoryCommit
$commit,
770 $request = $this->getRequest();
771 $viewer = $request->getUser();
773 // TODO: This is pretty awkward, unify the CSS between Diffusion and
774 // Differential better.
775 require_celerity_resource('differential-core-view-css');
777 $comment_view = id(new DiffusionCommitEditEngine())
779 ->buildEditEngineCommentView($commit);
781 $comment_view->setTransactionTimeline($timeline);
783 return $comment_view;
786 private function buildMergesTable(PhabricatorRepositoryCommit
$commit) {
787 $viewer = $this->getViewer();
788 $drequest = $this->getDiffusionRequest();
789 $repository = $drequest->getRepository();
791 $merges = $this->getCommitMerges();
796 $limit = $this->getMergeDisplayLimit();
799 if (count($merges) > $limit) {
800 $merges = array_slice($merges, 0, $limit);
801 $caption = new PHUIInfoView();
802 $caption->setSeverity(PHUIInfoView
::SEVERITY_NOTICE
);
803 $caption->appendChild(
805 'This commit merges a very large number of changes. '.
806 'Only the first %s are shown.',
807 new PhutilNumber($limit)));
810 $commit_list = id(new DiffusionCommitGraphView())
812 ->setDiffusionRequest($drequest)
813 ->setHistory($merges);
815 $panel = id(new PHUIObjectBoxView())
816 ->setHeaderText(pht('Merged Changes'))
817 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
818 ->setObjectList($commit_list->newObjectItemListView());
820 $panel->setInfoView($caption);
826 private function buildCurtain(
827 PhabricatorRepositoryCommit
$commit,
828 PhabricatorRepository
$repository) {
830 $request = $this->getRequest();
831 $viewer = $this->getViewer();
832 $curtain = $this->newCurtainView($commit);
834 $can_edit = PhabricatorPolicyFilter
::hasCapability(
837 PhabricatorPolicyCapability
::CAN_EDIT
);
839 $id = $commit->getID();
840 $edit_uri = $this->getApplicationURI("/commit/edit/{$id}/");
842 $action = id(new PhabricatorActionView())
843 ->setName(pht('Edit Commit'))
845 ->setIcon('fa-pencil')
846 ->setDisabled(!$can_edit)
847 ->setWorkflow(!$can_edit);
848 $curtain->addAction($action);
850 $action = id(new PhabricatorActionView())
851 ->setName(pht('Download Raw Diff'))
852 ->setHref($request->getRequestURI()->alter('diff', true))
853 ->setIcon('fa-download');
854 $curtain->addAction($action);
856 $relationship_list = PhabricatorObjectRelationshipList
::newForObject(
860 $relationship_submenu = $relationship_list->newActionMenu();
861 if ($relationship_submenu) {
862 $curtain->addAction($relationship_submenu);
868 private function buildRawDiffResponse(DiffusionRequest
$drequest) {
869 $diff_info = $this->callConduitWithDiffusionRequest(
870 'diffusion.rawdiffquery',
872 'commit' => $drequest->getCommit(),
873 'path' => $drequest->getPath(),
876 $file_phid = $diff_info['filePHID'];
878 $file = id(new PhabricatorFileQuery())
879 ->setViewer($this->getViewer())
880 ->withPHIDs(array($file_phid))
885 'Failed to load file ("%s") returned by "%s".',
887 'diffusion.rawdiffquery'));
890 return $file->getRedirectResponse();
893 private function renderAuditStatusView(
894 PhabricatorRepositoryCommit
$commit,
895 array $audit_requests) {
896 assert_instances_of($audit_requests, 'PhabricatorRepositoryAuditRequest');
897 $viewer = $this->getViewer();
899 $view = new PHUIStatusListView();
900 foreach ($audit_requests as $request) {
901 $status = $request->getAuditRequestStatusObject();
903 $item = new PHUIStatusItemView();
905 $status->getIconIcon(),
906 $status->getIconColor(),
907 $status->getStatusName());
909 $auditor_phid = $request->getAuditorPHID();
910 $target = $viewer->renderHandle($auditor_phid);
911 $item->setTarget($target);
913 if ($commit->hasAuditAuthority($viewer, $request)) {
914 $item->setHighlighted(true);
917 $view->addItem($item);
923 private function linkBugtraq($corpus) {
924 $url = PhabricatorEnv
::getEnvConfig('bugtraq.url');
929 $regexes = PhabricatorEnv
::getEnvConfig('bugtraq.logregex');
934 $parser = id(new PhutilBugtraqParser())
935 ->setBugtraqPattern("[[ {$url} | %BUGID% ]]")
936 ->setBugtraqCaptureExpression(array_shift($regexes));
938 $select = array_shift($regexes);
940 $parser->setBugtraqSelectExpression($select);
943 return $parser->processCorpus($corpus);
946 private function buildTableOfContents(
951 $drequest = $this->getDiffusionRequest();
952 $viewer = $this->getViewer();
954 $toc_view = id(new PHUIDiffTableOfContentsListView())
957 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
);
960 $toc_view->setInfoView($info_view);
963 // TODO: This is hacky, we just want access to the linkX() methods on
965 $diffusion_view = id(new DiffusionEmptyResultView())
966 ->setDiffusionRequest($drequest);
968 $have_owners = PhabricatorApplication
::isClassInstalledForViewer(
969 'PhabricatorOwnersApplication',
973 $have_owners = false;
977 if ($viewer->getPHID()) {
978 $packages = id(new PhabricatorOwnersPackageQuery())
980 ->withStatuses(array(PhabricatorOwnersPackage
::STATUS_ACTIVE
))
981 ->withAuthorityPHIDs(array($viewer->getPHID()))
983 $toc_view->setAuthorityPackages($packages);
986 $repository = $drequest->getRepository();
987 $repository_phid = $repository->getPHID();
989 $control_query = id(new PhabricatorOwnersPackageQuery())
991 ->withStatuses(array(PhabricatorOwnersPackage
::STATUS_ACTIVE
))
992 ->withControl($repository_phid, mpull($changesets, 'getFilename'));
993 $control_query->execute();
996 foreach ($changesets as $changeset_id => $changeset) {
997 $path = $changeset->getFilename();
998 $anchor = $changeset->getAnchorName();
1000 $history_link = $diffusion_view->linkHistory($path);
1001 $browse_link = $diffusion_view->linkBrowse(
1004 'type' => $changeset->getFileType(),
1007 $item = id(new PHUIDiffTableOfContentsItemView())
1008 ->setChangeset($changeset)
1009 ->setAnchor($anchor)
1018 $packages = $control_query->getControllingPackagesForPath(
1020 $changeset->getFilename());
1021 $item->setPackages($packages);
1024 $toc_view->addItem($item);
1030 private function loadCommitState() {
1031 $viewer = $this->getViewer();
1032 $drequest = $this->getDiffusionRequest();
1033 $repository = $drequest->getRepository();
1034 $commit = $drequest->getCommit();
1036 // TODO: We could use futures here and resolve these calls in parallel.
1038 $exceptions = array();
1041 $parent_refs = $this->callConduitWithDiffusionRequest(
1042 'diffusion.commitparentsquery',
1044 'commit' => $commit,
1048 $parents = id(new DiffusionCommitQuery())
1049 ->setViewer($viewer)
1050 ->withRepository($repository)
1051 ->withIdentifiers($parent_refs)
1057 $this->commitParents
= $parents;
1058 } catch (Exception
$ex) {
1059 $this->commitParents
= false;
1060 $exceptions[] = $ex;
1063 $merge_limit = $this->getMergeDisplayLimit();
1066 if ($repository->isSVN()) {
1067 $this->commitMerges
= array();
1069 $merges = $this->callConduitWithDiffusionRequest(
1070 'diffusion.mergedcommitsquery',
1072 'commit' => $commit,
1073 'limit' => $merge_limit +
1,
1075 $this->commitMerges
= DiffusionPathChange
::newFromConduit($merges);
1077 } catch (Exception
$ex) {
1078 $this->commitMerges
= false;
1079 $exceptions[] = $ex;
1084 if ($repository->isGit()) {
1085 $refs = $this->callConduitWithDiffusionRequest(
1086 'diffusion.refsquery',
1088 'commit' => $commit,
1094 $this->commitRefs
= $refs;
1095 } catch (Exception
$ex) {
1096 $this->commitRefs
= false;
1097 $exceptions[] = $ex;
1101 $exists = $this->callConduitWithDiffusionRequest(
1102 'diffusion.existsquery',
1104 'commit' => $commit,
1108 $this->commitExists
= true;
1109 foreach ($exceptions as $exception) {
1110 $this->commitErrors
[] = $exception->getMessage();
1113 $this->commitExists
= false;
1114 $this->commitErrors
[] = pht(
1115 'This commit no longer exists in the repository. It may have '.
1116 'been part of a branch which was deleted.');
1119 $this->commitExists
= true;
1120 $this->commitErrors
= array();
1124 private function getMergeDisplayLimit() {
1128 private function getCommitExists() {
1129 if ($this->commitExists
=== null) {
1130 $this->loadCommitState();
1133 return $this->commitExists
;
1136 private function getCommitParents() {
1137 if ($this->commitParents
=== null) {
1138 $this->loadCommitState();
1141 return $this->commitParents
;
1144 private function getCommitRefs() {
1145 if ($this->commitRefs
=== null) {
1146 $this->loadCommitState();
1149 return $this->commitRefs
;
1152 private function getCommitMerges() {
1153 if ($this->commitMerges
=== null) {
1154 $this->loadCommitState();
1157 return $this->commitMerges
;
1160 private function getCommitErrors() {
1161 if ($this->commitErrors
=== null) {
1162 $this->loadCommitState();
1165 return $this->commitErrors
;