2011-03-13 01:17:34 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class DiffusionRepositoryController extends DiffusionController {
|
2011-03-13 01:17:34 +01:00
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$drequest = $this->diffusionRequest;
|
|
|
|
|
|
|
|
$content = array();
|
|
|
|
|
|
|
|
$crumbs = $this->buildCrumbs();
|
|
|
|
$content[] = $crumbs;
|
|
|
|
|
2012-03-08 21:46:19 +01:00
|
|
|
$content[] = $this->buildPropertiesTable($drequest->getRepository());
|
|
|
|
|
2011-03-13 01:17:34 +01:00
|
|
|
$history_query = DiffusionHistoryQuery::newFromDiffusionRequest(
|
|
|
|
$drequest);
|
|
|
|
$history_query->setLimit(15);
|
2012-03-24 01:11:15 +01:00
|
|
|
$history_query->needParents(true);
|
2011-03-13 01:17:34 +01:00
|
|
|
$history = $history_query->loadHistory();
|
2011-04-03 01:39:23 +02:00
|
|
|
|
|
|
|
$browse_query = DiffusionBrowseQuery::newFromDiffusionRequest($drequest);
|
|
|
|
$browse_results = $browse_query->loadPaths();
|
|
|
|
|
|
|
|
$phids = array();
|
|
|
|
|
|
|
|
foreach ($history as $item) {
|
|
|
|
$data = $item->getCommitData();
|
|
|
|
if ($data) {
|
|
|
|
if ($data->getCommitDetail('authorPHID')) {
|
|
|
|
$phids[$data->getCommitDetail('authorPHID')] = true;
|
|
|
|
}
|
2012-05-23 17:34:36 +02:00
|
|
|
if ($data->getCommitDetail('committerPHID')) {
|
|
|
|
$phids[$data->getCommitDetail('committerPHID')] = true;
|
|
|
|
}
|
2011-04-03 01:39:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($browse_results as $item) {
|
|
|
|
$data = $item->getLastCommitData();
|
|
|
|
if ($data) {
|
|
|
|
if ($data->getCommitDetail('authorPHID')) {
|
|
|
|
$phids[$data->getCommitDetail('authorPHID')] = true;
|
|
|
|
}
|
2012-05-23 17:34:36 +02:00
|
|
|
if ($data->getCommitDetail('committerPHID')) {
|
|
|
|
$phids[$data->getCommitDetail('committerPHID')] = true;
|
|
|
|
}
|
2011-04-03 01:39:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$phids = array_keys($phids);
|
2012-09-05 04:02:56 +02:00
|
|
|
$handles = $this->loadViewerHandles($phids);
|
2011-04-03 01:39:23 +02:00
|
|
|
|
2011-03-13 01:17:34 +01:00
|
|
|
$history_table = new DiffusionHistoryTableView();
|
|
|
|
$history_table->setDiffusionRequest($drequest);
|
2011-04-03 01:39:23 +02:00
|
|
|
$history_table->setHandles($handles);
|
2011-03-13 01:17:34 +01:00
|
|
|
$history_table->setHistory($history);
|
2012-06-23 01:52:08 +02:00
|
|
|
$history_table->loadRevisions();
|
2012-03-24 01:11:15 +01:00
|
|
|
$history_table->setParents($history_query->getParents());
|
|
|
|
$history_table->setIsHead(true);
|
2011-03-13 01:17:34 +01:00
|
|
|
|
2011-03-13 07:51:40 +01:00
|
|
|
$callsign = $drequest->getRepository()->getCallsign();
|
|
|
|
$all = phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => "/diffusion/{$callsign}/history/",
|
|
|
|
),
|
|
|
|
'View Full Commit History');
|
|
|
|
|
2011-03-13 01:17:34 +01:00
|
|
|
$panel = new AphrontPanelView();
|
2011-03-13 07:51:40 +01:00
|
|
|
$panel->setHeader("Recent Commits · {$all}");
|
2011-03-13 01:17:34 +01:00
|
|
|
$panel->appendChild($history_table);
|
|
|
|
|
|
|
|
$content[] = $panel;
|
|
|
|
|
|
|
|
|
|
|
|
$browse_table = new DiffusionBrowseTableView();
|
|
|
|
$browse_table->setDiffusionRequest($drequest);
|
2011-04-03 01:39:23 +02:00
|
|
|
$browse_table->setHandles($handles);
|
|
|
|
$browse_table->setPaths($browse_results);
|
2012-08-02 21:22:50 +02:00
|
|
|
$browse_table->setUser($this->getRequest()->getUser());
|
2011-03-13 01:17:34 +01:00
|
|
|
|
|
|
|
$browse_panel = new AphrontPanelView();
|
|
|
|
$browse_panel->setHeader('Browse Repository');
|
|
|
|
$browse_panel->appendChild($browse_table);
|
|
|
|
|
|
|
|
$content[] = $browse_panel;
|
|
|
|
|
2012-04-18 17:02:08 +02:00
|
|
|
$content[] = $this->buildTagListTable($drequest);
|
|
|
|
|
2012-05-10 09:28:19 +02:00
|
|
|
$content[] = $this->buildBranchListTable($drequest);
|
2011-03-13 01:17:34 +01:00
|
|
|
|
2012-04-30 16:47:41 +02:00
|
|
|
$readme = $browse_query->renderReadme($browse_results);
|
|
|
|
if ($readme) {
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('README');
|
|
|
|
$panel->appendChild($readme);
|
|
|
|
$content[] = $panel;
|
|
|
|
}
|
|
|
|
|
2011-03-13 01:17:34 +01:00
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
$content,
|
|
|
|
array(
|
2012-01-20 22:27:32 +01:00
|
|
|
'title' => $drequest->getRepository()->getName(),
|
2011-03-13 01:17:34 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2012-03-08 21:46:19 +01:00
|
|
|
private function buildPropertiesTable(PhabricatorRepository $repository) {
|
|
|
|
|
|
|
|
$properties = array();
|
|
|
|
$properties['Name'] = $repository->getName();
|
|
|
|
$properties['Callsign'] = $repository->getCallsign();
|
|
|
|
$properties['Description'] = $repository->getDetail('description');
|
|
|
|
switch ($repository->getVersionControlSystem()) {
|
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
|
|
|
|
$properties['Clone URI'] = $repository->getPublicRemoteURI();
|
|
|
|
break;
|
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
|
|
|
$properties['Repository Root'] = $repository->getPublicRemoteURI();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($properties as $key => $value) {
|
|
|
|
$rows[] = array(
|
|
|
|
phutil_escape_html($key),
|
|
|
|
phutil_escape_html($value));
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = new AphrontTableView($rows);
|
|
|
|
$table->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'header',
|
|
|
|
'wide',
|
|
|
|
));
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Repository Properties');
|
|
|
|
$panel->appendChild($table);
|
|
|
|
|
|
|
|
return $panel;
|
|
|
|
}
|
|
|
|
|
2012-05-10 09:28:19 +02:00
|
|
|
private function buildBranchListTable(DiffusionRequest $drequest) {
|
|
|
|
if ($drequest->getBranch() !== null) {
|
|
|
|
$limit = 15;
|
|
|
|
|
|
|
|
$branch_query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
|
2012-05-10 23:18:49 +02:00
|
|
|
$branch_query->setLimit($limit + 1);
|
2012-05-10 09:28:19 +02:00
|
|
|
$branches = $branch_query->loadBranches();
|
|
|
|
|
|
|
|
if (!$branches) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$more_branches = (count($branches) > $limit);
|
|
|
|
$branches = array_slice($branches, 0, $limit);
|
|
|
|
|
|
|
|
$commits = id(new PhabricatorAuditCommitQuery())
|
|
|
|
->withIdentifiers(
|
|
|
|
$drequest->getRepository()->getID(),
|
|
|
|
mpull($branches, 'getHeadCommitIdentifier'))
|
|
|
|
->needCommitData(true)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$table = new DiffusionBranchTableView();
|
|
|
|
$table->setDiffusionRequest($drequest);
|
|
|
|
$table->setBranches($branches);
|
|
|
|
$table->setCommits($commits);
|
|
|
|
$table->setUser($this->getRequest()->getUser());
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Branches');
|
|
|
|
|
|
|
|
if ($more_branches) {
|
2012-05-10 23:18:49 +02:00
|
|
|
$panel->setCaption('Showing ' . $limit . ' branches.');
|
2012-05-10 09:28:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$panel->addButton(
|
2012-05-10 23:18:49 +02:00
|
|
|
phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $drequest->generateURI(
|
2012-05-10 09:28:19 +02:00
|
|
|
array(
|
2012-05-10 23:18:49 +02:00
|
|
|
'action' => 'branches',
|
|
|
|
)),
|
|
|
|
'class' => 'grey button',
|
|
|
|
),
|
|
|
|
"Show All Branches \xC2\xBB"));
|
2012-05-10 09:28:19 +02:00
|
|
|
|
|
|
|
$panel->appendChild($table);
|
|
|
|
|
|
|
|
return $panel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-04-18 17:02:08 +02:00
|
|
|
private function buildTagListTable(DiffusionRequest $drequest) {
|
2012-05-10 09:28:19 +02:00
|
|
|
$tag_limit = 15;
|
2012-04-19 18:39:19 +02:00
|
|
|
|
2012-04-18 17:02:08 +02:00
|
|
|
$query = DiffusionTagListQuery::newFromDiffusionRequest($drequest);
|
2012-04-19 18:39:19 +02:00
|
|
|
$query->setLimit($tag_limit + 1);
|
2012-04-18 17:02:08 +02:00
|
|
|
$tags = $query->loadTags();
|
|
|
|
|
|
|
|
if (!$tags) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-04-19 18:39:19 +02:00
|
|
|
$more_tags = (count($tags) > $tag_limit);
|
|
|
|
$tags = array_slice($tags, 0, $tag_limit);
|
|
|
|
|
2012-04-18 17:02:08 +02:00
|
|
|
$commits = id(new PhabricatorAuditCommitQuery())
|
|
|
|
->withIdentifiers(
|
|
|
|
$drequest->getRepository()->getID(),
|
|
|
|
mpull($tags, 'getCommitIdentifier'))
|
|
|
|
->needCommitData(true)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$view = new DiffusionTagListView();
|
|
|
|
$view->setDiffusionRequest($drequest);
|
|
|
|
$view->setTags($tags);
|
|
|
|
$view->setUser($this->getRequest()->getUser());
|
|
|
|
$view->setCommits($commits);
|
|
|
|
|
|
|
|
$phids = $view->getRequiredHandlePHIDs();
|
2012-09-05 04:02:56 +02:00
|
|
|
$handles = $this->loadViewerHandles($phids);
|
2012-04-18 17:02:08 +02:00
|
|
|
$view->setHandles($handles);
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Tags');
|
2012-04-19 18:39:19 +02:00
|
|
|
|
|
|
|
if ($more_tags) {
|
|
|
|
$panel->setCaption('Showing the '.$tag_limit.' most recent tags.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$panel->addButton(
|
|
|
|
phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $drequest->generateURI(
|
|
|
|
array(
|
|
|
|
'action' => 'tags',
|
|
|
|
)),
|
|
|
|
'class' => 'grey button',
|
|
|
|
),
|
|
|
|
"Show All Tags \xC2\xBB"));
|
2012-04-18 17:02:08 +02:00
|
|
|
$panel->appendChild($view);
|
|
|
|
|
|
|
|
return $panel;
|
|
|
|
}
|
|
|
|
|
2011-03-13 01:17:34 +01:00
|
|
|
}
|