Path: blob/master/src/applications/diffusion/controller/DiffusionCommitController.php
12242 views
<?php12final class DiffusionCommitController extends DiffusionController {34const CHANGES_LIMIT = 100;56private $commitParents;7private $commitRefs;8private $commitMerges;9private $commitErrors;10private $commitExists;1112public function shouldAllowPublic() {13return true;14}1516public function handleRequest(AphrontRequest $request) {17$response = $this->loadDiffusionContext();18if ($response) {19return $response;20}2122$drequest = $this->getDiffusionRequest();23$viewer = $request->getUser();24$repository = $drequest->getRepository();25$commit_identifier = $drequest->getCommit();2627// If this page is being accessed via "/source/xyz/commit/...", redirect28// to the canonical URI.29$repo_callsign = $request->getURIData('repositoryCallsign');30$has_callsign = $repo_callsign !== null && strlen($repo_callsign);31$repo_id = $request->getURIData('repositoryID');32$has_id = $repo_id !== null && strlen($repo_id);3334if (!$has_callsign && !$has_id) {35$canonical_uri = $repository->getCommitURI($commit_identifier);36return id(new AphrontRedirectResponse())37->setURI($canonical_uri);38}3940if ($request->getStr('diff')) {41return $this->buildRawDiffResponse($drequest);42}4344$commits = id(new DiffusionCommitQuery())45->setViewer($viewer)46->withRepository($repository)47->withIdentifiers(array($commit_identifier))48->needCommitData(true)49->needAuditRequests(true)50->needAuditAuthority(array($viewer))51->setLimit(100)52->needIdentities(true)53->execute();5455$multiple_results = count($commits) > 1;5657$crumbs = $this->buildCrumbs(array(58'commit' => !$multiple_results,59));60$crumbs->setBorder(true);6162if (!$commits) {63if (!$this->getCommitExists()) {64return new Aphront404Response();65}6667$error = id(new PHUIInfoView())68->setTitle(pht('Commit Still Parsing'))69->appendChild(70pht(71'Failed to load the commit because the commit has not been '.72'parsed yet.'));7374$title = pht('Commit Still Parsing');7576return $this->newPage()77->setTitle($title)78->setCrumbs($crumbs)79->appendChild($error);80} else if ($multiple_results) {8182$warning_message =83pht(84'The identifier %s is ambiguous and matches more than one commit.',85phutil_tag(86'strong',87array(),88$commit_identifier));8990$error = id(new PHUIInfoView())91->setTitle(pht('Ambiguous Commit'))92->setSeverity(PHUIInfoView::SEVERITY_WARNING)93->appendChild($warning_message);9495$list = id(new DiffusionCommitGraphView())96->setViewer($viewer)97->setCommits($commits);9899$crumbs->addTextCrumb(pht('Ambiguous Commit'));100101$matched_commits = id(new PHUITwoColumnView())102->setFooter(array(103$error,104$list,105));106107return $this->newPage()108->setTitle(pht('Ambiguous Commit'))109->setCrumbs($crumbs)110->appendChild($matched_commits);111} else {112$commit = head($commits);113}114115$audit_requests = $commit->getAudits();116117$commit_data = $commit->getCommitData();118$is_foreign = $commit_data->getCommitDetail('foreign-svn-stub');119$error_panel = null;120$unpublished_panel = null;121122$hard_limit = 2000;123124if ($commit->isImported()) {125$change_query = DiffusionPathChangeQuery::newFromDiffusionRequest(126$drequest);127$change_query->setLimit($hard_limit + 1);128$changes = $change_query->loadChanges();129} else {130$changes = array();131}132133$was_limited = (count($changes) > $hard_limit);134if ($was_limited) {135$changes = array_slice($changes, 0, $hard_limit);136}137138$count = count($changes);139140$is_unreadable = false;141$hint = null;142if (!$count || $commit->isUnreachable()) {143$hint = id(new DiffusionCommitHintQuery())144->setViewer($viewer)145->withRepositoryPHIDs(array($repository->getPHID()))146->withOldCommitIdentifiers(array($commit->getCommitIdentifier()))147->executeOne();148if ($hint) {149$is_unreadable = $hint->isUnreadable();150}151}152153if ($is_foreign) {154$subpath = $commit_data->getCommitDetail('svn-subpath');155156$error_panel = new PHUIInfoView();157$error_panel->setTitle(pht('Commit Not Tracked'));158$error_panel->setSeverity(PHUIInfoView::SEVERITY_WARNING);159$error_panel->appendChild(160pht(161"This Diffusion repository is configured to track only one ".162"subdirectory of the entire Subversion repository, and this commit ".163"didn't affect the tracked subdirectory ('%s'), so no ".164"information is available.",165$subpath));166} else {167$engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();168$engine->setConfig('viewer', $viewer);169170$commit_tag = $this->renderCommitHashTag($drequest);171$header = id(new PHUIHeaderView())172->setHeader(nonempty($commit->getSummary(), pht('Commit Detail')))173->setHeaderIcon('fa-code-fork')174->addTag($commit_tag);175176if (!$commit->isAuditStatusNoAudit()) {177$status = $commit->getAuditStatusObject();178179$icon = $status->getIcon();180$color = $status->getColor();181$status = $status->getName();182183$header->setStatus($icon, $color, $status);184}185186$curtain = $this->buildCurtain($commit, $repository);187$details = $this->buildPropertyListView(188$commit,189$commit_data,190$audit_requests);191192$message = $commit_data->getCommitMessage();193194$revision = $commit->getCommitIdentifier();195$message = $this->linkBugtraq($message);196$message = $engine->markupText($message);197198$detail_list = new PHUIPropertyListView();199$detail_list->addTextContent(200phutil_tag(201'div',202array(203'class' => 'diffusion-commit-message phabricator-remarkup',204),205$message));206207if ($commit->isUnreachable()) {208$did_rewrite = false;209if ($hint) {210if ($hint->isRewritten()) {211$rewritten = id(new DiffusionCommitQuery())212->setViewer($viewer)213->withRepository($repository)214->withIdentifiers(array($hint->getNewCommitIdentifier()))215->executeOne();216if ($rewritten) {217$did_rewrite = true;218$rewritten_uri = $rewritten->getURI();219$rewritten_name = $rewritten->getLocalName();220221$rewritten_link = phutil_tag(222'a',223array(224'href' => $rewritten_uri,225),226$rewritten_name);227228$this->commitErrors[] = pht(229'This commit was rewritten after it was published, which '.230'changed the commit hash. This old version of the commit is '.231'no longer reachable from any branch, tag or ref. The new '.232'version of this commit is %s.',233$rewritten_link);234}235}236}237238if (!$did_rewrite) {239$this->commitErrors[] = pht(240'This commit has been deleted in the repository: it is no longer '.241'reachable from any branch, tag, or ref.');242}243}244if (!$commit->isPermanentCommit()) {245$nonpermanent_tag = id(new PHUITagView())246->setType(PHUITagView::TYPE_SHADE)247->setName(pht('Unpublished'))248->setColor(PHUITagView::COLOR_ORANGE);249250$header->addTag($nonpermanent_tag);251252$holds = $commit_data->newPublisherHoldReasons();253254$reasons = array();255foreach ($holds as $hold) {256$reasons[] = array(257phutil_tag('strong', array(), pht('%s:', $hold->getName())),258' ',259$hold->getSummary(),260);261}262263if (!$holds) {264$reasons[] = pht('No further details are available.');265}266267$doc_href = PhabricatorEnv::getDoclink(268'Diffusion User Guide: Permanent Refs');269$doc_link = phutil_tag(270'a',271array(272'href' => $doc_href,273'target' => '_blank',274),275pht('Learn More'));276277$title = array(278pht('Unpublished Commit'),279pht(" \xC2\xB7 "),280$doc_link,281);282283$unpublished_panel = id(new PHUIInfoView())284->setTitle($title)285->setErrors($reasons)286->setSeverity(PHUIInfoView::SEVERITY_WARNING);287}288289290if ($this->getCommitErrors()) {291$error_panel = id(new PHUIInfoView())292->appendChild($this->getCommitErrors())293->setSeverity(PHUIInfoView::SEVERITY_WARNING);294}295}296297$timeline = $this->buildComments($commit);298$merge_table = $this->buildMergesTable($commit);299300$show_changesets = false;301$info_panel = null;302$change_list = null;303$change_table = null;304if ($is_unreadable) {305$info_panel = $this->renderStatusMessage(306pht('Unreadable Commit'),307pht(308'This commit has been marked as unreadable by an administrator. '.309'It may have been corrupted or created improperly by an external '.310'tool.'));311} else if ($is_foreign) {312// Don't render anything else.313} else if (!$commit->isImported()) {314$info_panel = $this->renderStatusMessage(315pht('Still Importing...'),316pht(317'This commit is still importing. Changes will be visible once '.318'the import finishes.'));319} else if (!count($changes)) {320$info_panel = $this->renderStatusMessage(321pht('Empty Commit'),322pht(323'This commit is empty and does not affect any paths.'));324} else if ($was_limited) {325$info_panel = $this->renderStatusMessage(326pht('Very Large Commit'),327pht(328'This commit is very large, and affects more than %d files. '.329'Changes are not shown.',330$hard_limit));331} else if (!$this->getCommitExists()) {332$info_panel = $this->renderStatusMessage(333pht('Commit No Longer Exists'),334pht('This commit no longer exists in the repository.'));335} else {336$show_changesets = true;337338// The user has clicked "Show All Changes", and we should show all the339// changes inline even if there are more than the soft limit.340$show_all_details = $request->getBool('show_all');341342$change_header = id(new PHUIHeaderView())343->setHeader(pht('Changes (%s)', new PhutilNumber($count)));344345$warning_view = null;346if ($count > self::CHANGES_LIMIT && !$show_all_details) {347$button = id(new PHUIButtonView())348->setText(pht('Show All Changes'))349->setHref('?show_all=true')350->setTag('a')351->setIcon('fa-files-o');352353$warning_view = id(new PHUIInfoView())354->setSeverity(PHUIInfoView::SEVERITY_WARNING)355->setTitle(pht('Very Large Commit'))356->appendChild(357pht('This commit is very large. Load each file individually.'));358359$change_header->addActionLink($button);360}361362$changesets = DiffusionPathChange::convertToDifferentialChangesets(363$viewer,364$changes);365366// TODO: This table and panel shouldn't really be separate, but we need367// to clean up the "Load All Files" interaction first.368$change_table = $this->buildTableOfContents(369$changesets,370$change_header,371$warning_view);372373$vcs = $repository->getVersionControlSystem();374switch ($vcs) {375case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:376$vcs_supports_directory_changes = true;377break;378case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:379case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:380$vcs_supports_directory_changes = false;381break;382default:383throw new Exception(pht('Unknown VCS.'));384}385386$references = array();387foreach ($changesets as $key => $changeset) {388$file_type = $changeset->getFileType();389if ($file_type == DifferentialChangeType::FILE_DIRECTORY) {390if (!$vcs_supports_directory_changes) {391unset($changesets[$key]);392continue;393}394}395396$references[$key] = $drequest->generateURI(397array(398'action' => 'rendering-ref',399'path' => $changeset->getFilename(),400));401}402403// TODO: Some parts of the views still rely on properties of the404// DifferentialChangeset. Make the objects ephemeral to make sure we don't405// accidentally save them, and then set their ID to the appropriate ID for406// this application (the path IDs).407$path_ids = array_flip(mpull($changes, 'getPath'));408foreach ($changesets as $changeset) {409$changeset->makeEphemeral();410$changeset->setID($path_ids[$changeset->getFilename()]);411}412413if ($count <= self::CHANGES_LIMIT || $show_all_details) {414$visible_changesets = $changesets;415} else {416$visible_changesets = array();417418$inlines = id(new DiffusionDiffInlineCommentQuery())419->setViewer($viewer)420->withCommitPHIDs(array($commit->getPHID()))421->withPublishedComments(true)422->withPublishableComments(true)423->execute();424$inlines = mpull($inlines, 'newInlineCommentObject');425426$path_ids = mpull($inlines, null, 'getPathID');427foreach ($changesets as $key => $changeset) {428if (array_key_exists($changeset->getID(), $path_ids)) {429$visible_changesets[$key] = $changeset;430}431}432}433434$change_list_title = $commit->getDisplayName();435436$change_list = new DifferentialChangesetListView();437$change_list->setTitle($change_list_title);438$change_list->setChangesets($changesets);439$change_list->setVisibleChangesets($visible_changesets);440$change_list->setRenderingReferences($references);441$change_list->setRenderURI($repository->getPathURI('diff/'));442$change_list->setRepository($repository);443$change_list->setUser($viewer);444$change_list->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);445446// TODO: Try to setBranch() to something reasonable here?447448$change_list->setStandaloneURI(449$repository->getPathURI('diff/'));450451$change_list->setRawFileURIs(452// TODO: Implement this, somewhat tricky if there's an octopus merge453// or whatever?454null,455$repository->getPathURI('diff/?view=r'));456457$change_list->setInlineCommentControllerURI(458'/diffusion/inline/edit/'.phutil_escape_uri($commit->getPHID()).'/');459460}461462$add_comment = $this->renderAddCommentPanel(463$commit,464$timeline);465466$filetree = id(new DifferentialFileTreeEngine())467->setViewer($viewer)468->setDisabled(!$show_changesets);469470if ($show_changesets) {471$filetree->setChangesets($changesets);472}473474$description_box = id(new PHUIObjectBoxView())475->setHeaderText(pht('Description'))476->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)477->appendChild($detail_list);478479$detail_box = id(new PHUIObjectBoxView())480->setHeaderText(pht('Details'))481->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)482->appendChild($details);483484$view = id(new PHUITwoColumnView())485->setHeader($header)486->setCurtain($curtain)487->setMainColumn(488array(489$unpublished_panel,490$error_panel,491$description_box,492$detail_box,493$timeline,494$merge_table,495$info_panel,496))497->setFooter(498array(499$change_table,500$change_list,501$add_comment,502));503504$main_content = array(505$crumbs,506$view,507);508509$main_content = $filetree->newView($main_content);510if (!$filetree->getDisabled()) {511$change_list->setFormationView($main_content);512}513514$page = $this->newPage()515->setTitle($commit->getDisplayName())516->setPageObjectPHIDS(array($commit->getPHID()))517->appendChild($main_content);518519return $page;520521}522523private function buildPropertyListView(524PhabricatorRepositoryCommit $commit,525PhabricatorRepositoryCommitData $data,526array $audit_requests) {527528$viewer = $this->getViewer();529$commit_phid = $commit->getPHID();530$drequest = $this->getDiffusionRequest();531$repository = $drequest->getRepository();532533$view = id(new PHUIPropertyListView())534->setUser($this->getRequest()->getUser())535->setObject($commit);536537$edge_query = id(new PhabricatorEdgeQuery())538->withSourcePHIDs(array($commit_phid))539->withEdgeTypes(array(540DiffusionCommitHasTaskEdgeType::EDGECONST,541DiffusionCommitHasRevisionEdgeType::EDGECONST,542DiffusionCommitRevertsCommitEdgeType::EDGECONST,543DiffusionCommitRevertedByCommitEdgeType::EDGECONST,544));545546$edges = $edge_query->execute();547548$task_phids = array_keys(549$edges[$commit_phid][DiffusionCommitHasTaskEdgeType::EDGECONST]);550$revision_phid = key(551$edges[$commit_phid][DiffusionCommitHasRevisionEdgeType::EDGECONST]);552553$reverts_phids = array_keys(554$edges[$commit_phid][DiffusionCommitRevertsCommitEdgeType::EDGECONST]);555$reverted_by_phids = array_keys(556$edges[$commit_phid][DiffusionCommitRevertedByCommitEdgeType::EDGECONST]);557558$phids = $edge_query->getDestinationPHIDs(array($commit_phid));559560561if ($data->getCommitDetail('reviewerPHID')) {562$phids[] = $data->getCommitDetail('reviewerPHID');563}564565$phids[] = $commit->getCommitterDisplayPHID();566$phids[] = $commit->getAuthorDisplayPHID();567568// NOTE: We should never normally have more than a single push log, but569// it can occur naturally if a commit is pushed, then the branch it was570// on is deleted, then the commit is pushed again (or through other similar571// chains of events). This should be rare, but does not indicate a bug572// or data issue.573574// NOTE: We never query push logs in SVN because the committer is always575// the pusher and the commit time is always the push time; the push log576// is redundant and we save a query by skipping it.577578$push_logs = array();579if ($repository->isHosted() && !$repository->isSVN()) {580$push_logs = id(new PhabricatorRepositoryPushLogQuery())581->setViewer($viewer)582->withRepositoryPHIDs(array($repository->getPHID()))583->withNewRefs(array($commit->getCommitIdentifier()))584->withRefTypes(array(PhabricatorRepositoryPushLog::REFTYPE_COMMIT))585->execute();586foreach ($push_logs as $log) {587$phids[] = $log->getPusherPHID();588}589}590591$handles = array();592if ($phids) {593$handles = $this->loadViewerHandles($phids);594}595596$props = array();597598if ($audit_requests) {599$user_requests = array();600$other_requests = array();601602foreach ($audit_requests as $audit_request) {603if ($audit_request->isUser()) {604$user_requests[] = $audit_request;605} else {606$other_requests[] = $audit_request;607}608}609610if ($user_requests) {611$view->addProperty(612pht('Auditors'),613$this->renderAuditStatusView($commit, $user_requests));614}615616if ($other_requests) {617$view->addProperty(618pht('Group Auditors'),619$this->renderAuditStatusView($commit, $other_requests));620}621}622623$provenance_list = new PHUIStatusListView();624625$author_view = $commit->newCommitAuthorView($viewer);626if ($author_view) {627$author_date = $data->getAuthorEpoch();628$author_date = phabricator_datetime($author_date, $viewer);629630$provenance_list->addItem(631id(new PHUIStatusItemView())632->setTarget($author_view)633->setNote(pht('Authored on %s', $author_date)));634}635636if (!$commit->isAuthorSameAsCommitter()) {637$committer_view = $commit->newCommitCommitterView($viewer);638if ($committer_view) {639$committer_date = $commit->getEpoch();640$committer_date = phabricator_datetime($committer_date, $viewer);641642$provenance_list->addItem(643id(new PHUIStatusItemView())644->setTarget($committer_view)645->setNote(pht('Committed on %s', $committer_date)));646}647}648649if ($push_logs) {650$pushed_list = new PHUIStatusListView();651652foreach ($push_logs as $push_log) {653$pusher_date = $push_log->getEpoch();654$pusher_date = phabricator_datetime($pusher_date, $viewer);655656$pusher_view = $handles[$push_log->getPusherPHID()]->renderLink();657658$provenance_list->addItem(659id(new PHUIStatusItemView())660->setTarget($pusher_view)661->setNote(pht('Pushed on %s', $pusher_date)));662}663}664665$view->addProperty(pht('Provenance'), $provenance_list);666667$reviewer_phid = $data->getCommitDetail('reviewerPHID');668if ($reviewer_phid) {669$view->addProperty(670pht('Reviewer'),671$handles[$reviewer_phid]->renderLink());672}673674if ($revision_phid) {675$view->addProperty(676pht('Differential Revision'),677$handles[$revision_phid]->renderLink());678}679680$parents = $this->getCommitParents();681if ($parents) {682$view->addProperty(683pht('Parents'),684$viewer->renderHandleList(mpull($parents, 'getPHID')));685}686687if ($this->getCommitExists()) {688$view->addProperty(689pht('Branches'),690phutil_tag(691'span',692array(693'id' => 'commit-branches',694),695pht('Unknown')));696697$view->addProperty(698pht('Tags'),699phutil_tag(700'span',701array(702'id' => 'commit-tags',703),704pht('Unknown')));705706$identifier = $commit->getCommitIdentifier();707$root = $repository->getPathURI("commit/{$identifier}");708Javelin::initBehavior(709'diffusion-commit-branches',710array(711$root.'/branches/' => 'commit-branches',712$root.'/tags/' => 'commit-tags',713));714}715716$refs = $this->getCommitRefs();717if ($refs) {718$ref_links = array();719foreach ($refs as $ref_data) {720$ref_links[] = phutil_tag(721'a',722array(723'href' => $ref_data['href'],724),725$ref_data['ref']);726}727$view->addProperty(728pht('References'),729phutil_implode_html(', ', $ref_links));730}731732if ($reverts_phids) {733$view->addProperty(734pht('Reverts'),735$viewer->renderHandleList($reverts_phids));736}737738if ($reverted_by_phids) {739$view->addProperty(740pht('Reverted By'),741$viewer->renderHandleList($reverted_by_phids));742}743744if ($task_phids) {745$task_list = array();746foreach ($task_phids as $phid) {747$task_list[] = $handles[$phid]->renderLink();748}749$task_list = phutil_implode_html(phutil_tag('br'), $task_list);750$view->addProperty(751pht('Tasks'),752$task_list);753}754755return $view;756}757758private function buildComments(PhabricatorRepositoryCommit $commit) {759$timeline = $this->buildTransactionTimeline(760$commit,761new PhabricatorAuditTransactionQuery());762763$timeline->setQuoteRef($commit->getMonogram());764765return $timeline;766}767768private function renderAddCommentPanel(769PhabricatorRepositoryCommit $commit,770$timeline) {771772$request = $this->getRequest();773$viewer = $request->getUser();774775// TODO: This is pretty awkward, unify the CSS between Diffusion and776// Differential better.777require_celerity_resource('differential-core-view-css');778779$comment_view = id(new DiffusionCommitEditEngine())780->setViewer($viewer)781->buildEditEngineCommentView($commit);782783$comment_view->setTransactionTimeline($timeline);784785return $comment_view;786}787788private function buildMergesTable(PhabricatorRepositoryCommit $commit) {789$viewer = $this->getViewer();790$drequest = $this->getDiffusionRequest();791$repository = $drequest->getRepository();792793$merges = $this->getCommitMerges();794if (!$merges) {795return null;796}797798$limit = $this->getMergeDisplayLimit();799800$caption = null;801if (count($merges) > $limit) {802$merges = array_slice($merges, 0, $limit);803$caption = new PHUIInfoView();804$caption->setSeverity(PHUIInfoView::SEVERITY_NOTICE);805$caption->appendChild(806pht(807'This commit merges a very large number of changes. '.808'Only the first %s are shown.',809new PhutilNumber($limit)));810}811812$commit_list = id(new DiffusionCommitGraphView())813->setViewer($viewer)814->setDiffusionRequest($drequest)815->setHistory($merges);816817$panel = id(new PHUIObjectBoxView())818->setHeaderText(pht('Merged Changes'))819->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)820->setObjectList($commit_list->newObjectItemListView());821if ($caption) {822$panel->setInfoView($caption);823}824825return $panel;826}827828private function buildCurtain(829PhabricatorRepositoryCommit $commit,830PhabricatorRepository $repository) {831832$request = $this->getRequest();833$viewer = $this->getViewer();834$curtain = $this->newCurtainView($commit);835836$can_edit = PhabricatorPolicyFilter::hasCapability(837$viewer,838$commit,839PhabricatorPolicyCapability::CAN_EDIT);840841$id = $commit->getID();842$edit_uri = $this->getApplicationURI("/commit/edit/{$id}/");843844$action = id(new PhabricatorActionView())845->setName(pht('Edit Commit'))846->setHref($edit_uri)847->setIcon('fa-pencil')848->setDisabled(!$can_edit)849->setWorkflow(!$can_edit);850$curtain->addAction($action);851852$action = id(new PhabricatorActionView())853->setName(pht('Download Raw Diff'))854->setHref($request->getRequestURI()->alter('diff', true))855->setIcon('fa-download');856$curtain->addAction($action);857858$relationship_list = PhabricatorObjectRelationshipList::newForObject(859$viewer,860$commit);861862$relationship_submenu = $relationship_list->newActionMenu();863if ($relationship_submenu) {864$curtain->addAction($relationship_submenu);865}866867return $curtain;868}869870private function buildRawDiffResponse(DiffusionRequest $drequest) {871$diff_info = $this->callConduitWithDiffusionRequest(872'diffusion.rawdiffquery',873array(874'commit' => $drequest->getCommit(),875'path' => $drequest->getPath(),876));877878$file_phid = $diff_info['filePHID'];879880$file = id(new PhabricatorFileQuery())881->setViewer($this->getViewer())882->withPHIDs(array($file_phid))883->executeOne();884if (!$file) {885throw new Exception(886pht(887'Failed to load file ("%s") returned by "%s".',888$file_phid,889'diffusion.rawdiffquery'));890}891892return $file->getRedirectResponse();893}894895private function renderAuditStatusView(896PhabricatorRepositoryCommit $commit,897array $audit_requests) {898assert_instances_of($audit_requests, 'PhabricatorRepositoryAuditRequest');899$viewer = $this->getViewer();900901$view = new PHUIStatusListView();902foreach ($audit_requests as $request) {903$status = $request->getAuditRequestStatusObject();904905$item = new PHUIStatusItemView();906$item->setIcon(907$status->getIconIcon(),908$status->getIconColor(),909$status->getStatusName());910911$auditor_phid = $request->getAuditorPHID();912$target = $viewer->renderHandle($auditor_phid);913$item->setTarget($target);914915if ($commit->hasAuditAuthority($viewer, $request)) {916$item->setHighlighted(true);917}918919$view->addItem($item);920}921922return $view;923}924925private function linkBugtraq($corpus) {926$url = PhabricatorEnv::getEnvConfig('bugtraq.url');927if ($url === null || !strlen($url)) {928return $corpus;929}930931$regexes = PhabricatorEnv::getEnvConfig('bugtraq.logregex');932if (!$regexes) {933return $corpus;934}935936$parser = id(new PhutilBugtraqParser())937->setBugtraqPattern("[[ {$url} | %BUGID% ]]")938->setBugtraqCaptureExpression(array_shift($regexes));939940$select = array_shift($regexes);941if ($select) {942$parser->setBugtraqSelectExpression($select);943}944945return $parser->processCorpus($corpus);946}947948private function buildTableOfContents(949array $changesets,950$header,951$info_view) {952953$drequest = $this->getDiffusionRequest();954$viewer = $this->getViewer();955956$toc_view = id(new PHUIDiffTableOfContentsListView())957->setUser($viewer)958->setHeader($header)959->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);960961if ($info_view) {962$toc_view->setInfoView($info_view);963}964965// TODO: This is hacky, we just want access to the linkX() methods on966// DiffusionView.967$diffusion_view = id(new DiffusionEmptyResultView())968->setDiffusionRequest($drequest);969970$have_owners = PhabricatorApplication::isClassInstalledForViewer(971'PhabricatorOwnersApplication',972$viewer);973974if (!$changesets) {975$have_owners = false;976}977978if ($have_owners) {979if ($viewer->getPHID()) {980$packages = id(new PhabricatorOwnersPackageQuery())981->setViewer($viewer)982->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))983->withAuthorityPHIDs(array($viewer->getPHID()))984->execute();985$toc_view->setAuthorityPackages($packages);986}987988$repository = $drequest->getRepository();989$repository_phid = $repository->getPHID();990991$control_query = id(new PhabricatorOwnersPackageQuery())992->setViewer($viewer)993->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))994->withControl($repository_phid, mpull($changesets, 'getFilename'));995$control_query->execute();996}997998foreach ($changesets as $changeset_id => $changeset) {999$path = $changeset->getFilename();1000$anchor = $changeset->getAnchorName();10011002$history_link = $diffusion_view->linkHistory($path);1003$browse_link = $diffusion_view->linkBrowse(1004$path,1005array(1006'type' => $changeset->getFileType(),1007));10081009$item = id(new PHUIDiffTableOfContentsItemView())1010->setChangeset($changeset)1011->setAnchor($anchor)1012->setContext(1013array(1014$history_link,1015' ',1016$browse_link,1017));10181019if ($have_owners) {1020$packages = $control_query->getControllingPackagesForPath(1021$repository_phid,1022$changeset->getFilename());1023$item->setPackages($packages);1024}10251026$toc_view->addItem($item);1027}10281029return $toc_view;1030}10311032private function loadCommitState() {1033$viewer = $this->getViewer();1034$drequest = $this->getDiffusionRequest();1035$repository = $drequest->getRepository();1036$commit = $drequest->getCommit();10371038// TODO: We could use futures here and resolve these calls in parallel.10391040$exceptions = array();10411042try {1043$parent_refs = $this->callConduitWithDiffusionRequest(1044'diffusion.commitparentsquery',1045array(1046'commit' => $commit,1047));10481049if ($parent_refs) {1050$parents = id(new DiffusionCommitQuery())1051->setViewer($viewer)1052->withRepository($repository)1053->withIdentifiers($parent_refs)1054->execute();1055} else {1056$parents = array();1057}10581059$this->commitParents = $parents;1060} catch (Exception $ex) {1061$this->commitParents = false;1062$exceptions[] = $ex;1063}10641065$merge_limit = $this->getMergeDisplayLimit();10661067try {1068if ($repository->isSVN()) {1069$this->commitMerges = array();1070} else {1071$merges = $this->callConduitWithDiffusionRequest(1072'diffusion.mergedcommitsquery',1073array(1074'commit' => $commit,1075'limit' => $merge_limit + 1,1076));1077$this->commitMerges = DiffusionPathChange::newFromConduit($merges);1078}1079} catch (Exception $ex) {1080$this->commitMerges = false;1081$exceptions[] = $ex;1082}108310841085try {1086if ($repository->isGit()) {1087$refs = $this->callConduitWithDiffusionRequest(1088'diffusion.refsquery',1089array(1090'commit' => $commit,1091));1092} else {1093$refs = array();1094}10951096$this->commitRefs = $refs;1097} catch (Exception $ex) {1098$this->commitRefs = false;1099$exceptions[] = $ex;1100}11011102if ($exceptions) {1103$exists = $this->callConduitWithDiffusionRequest(1104'diffusion.existsquery',1105array(1106'commit' => $commit,1107));11081109if ($exists) {1110$this->commitExists = true;1111foreach ($exceptions as $exception) {1112$this->commitErrors[] = $exception->getMessage();1113}1114} else {1115$this->commitExists = false;1116$this->commitErrors[] = pht(1117'This commit no longer exists in the repository. It may have '.1118'been part of a branch which was deleted.');1119}1120} else {1121$this->commitExists = true;1122$this->commitErrors = array();1123}1124}11251126private function getMergeDisplayLimit() {1127return 50;1128}11291130private function getCommitExists() {1131if ($this->commitExists === null) {1132$this->loadCommitState();1133}11341135return $this->commitExists;1136}11371138private function getCommitParents() {1139if ($this->commitParents === null) {1140$this->loadCommitState();1141}11421143return $this->commitParents;1144}11451146private function getCommitRefs() {1147if ($this->commitRefs === null) {1148$this->loadCommitState();1149}11501151return $this->commitRefs;1152}11531154private function getCommitMerges() {1155if ($this->commitMerges === null) {1156$this->loadCommitState();1157}11581159return $this->commitMerges;1160}11611162private function getCommitErrors() {1163if ($this->commitErrors === null) {1164$this->loadCommitState();1165}11661167return $this->commitErrors;1168}116911701171}117211731174