Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/diffusion/controller/base/DiffusionController.php b/src/applications/diffusion/controller/base/DiffusionController.php
index b128f52dd8..a62d6bb30b 100644
--- a/src/applications/diffusion/controller/base/DiffusionController.php
+++ b/src/applications/diffusion/controller/base/DiffusionController.php
@@ -1,309 +1,309 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
abstract class DiffusionController extends PhabricatorController {
protected $diffusionRequest;
public function willProcessRequest(array $data) {
if (isset($data['callsign'])) {
$drequest = DiffusionRequest::newFromAphrontRequestDictionary($data);
$this->diffusionRequest = $drequest;
}
}
public function setDiffusionRequest(DiffusionRequest $request) {
$this->diffusionRequest = $request;
return $this;
}
protected function getDiffusionRequest() {
if (!$this->diffusionRequest) {
throw new Exception("No Diffusion request object!");
}
return $this->diffusionRequest;
}
public function buildStandardPageResponse($view, array $data) {
$page = $this->buildStandardPageView();
$page->setApplicationName('Diffusion');
$page->setBaseURI('/diffusion/');
$page->setTitle(idx($data, 'title'));
$page->setGlyph("\xE2\x89\x88");
$page->setTabs(
array(
'help' => array(
'href' => PhabricatorEnv::getDoclink(
'article/Diffusion_User_Guide.html'),
'name' => 'Help',
),
),
null);
$page->setSearchDefaultScope(PhabricatorSearchScope::SCOPE_COMMITS);
$page->appendChild($view);
$response = new AphrontWebpageResponse();
return $response->setContent($page->render());
}
final protected function buildSideNav($selected, $has_change_view) {
$nav = new AphrontSideNavView();
$navs = array(
'history' => 'History View',
'browse' => 'Browse View',
'change' => 'Change View',
);
if (!$has_change_view) {
unset($navs['change']);
}
$drequest = $this->getDiffusionRequest();
foreach ($navs as $action => $name) {
$href = $drequest->generateURI(
array(
'action' => $action,
));
$nav->addNavItem(
phutil_render_tag(
'a',
array(
'href' => $href,
'class' =>
($action == $selected
? 'aphront-side-nav-selected'
: null),
),
$name));
}
// TODO: URI encoding might need to be sorted out for this link.
$nav->addNavItem(
phutil_render_tag(
'a',
array(
'href' => '/owners/view/search/'.
'?repository='.phutil_escape_uri($drequest->getCallsign()).
'&path='.phutil_escape_uri('/'.$drequest->getPath()),
),
'Search Owners'));
return $nav;
}
public function buildCrumbs(array $spec = array()) {
$crumbs = new AphrontCrumbsView();
$crumb_list = $this->buildCrumbList($spec);
$crumbs->setCrumbs($crumb_list);
return $crumbs;
}
protected function buildOpenRevisions() {
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$path = $drequest->getPath();
$path_map = id(new DiffusionPathIDQuery(array($path)))->loadPathIDs();
$path_id = idx($path_map, $path);
if (!$path_id) {
return null;
}
$revisions = id(new DifferentialRevisionQuery())
->withPath($repository->getID(), $path_id)
->withStatus(DifferentialRevisionQuery::STATUS_OPEN)
->setOrder(DifferentialRevisionQuery::ORDER_PATH_MODIFIED)
->setLimit(10)
->needRelationships(true)
->execute();
if (!$revisions) {
return null;
}
$view = id(new DifferentialRevisionListView())
->setRevisions($revisions)
->setFields(DifferentialRevisionListView::getDefaultFields())
->setUser($this->getRequest()->getUser());
$phids = $view->getRequiredHandlePHIDs();
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
$view->setHandles($handles);
$panel = new AphrontPanelView();
$panel->setHeader('Pending Differential Revisions');
$panel->appendChild($view);
return $panel;
}
private function buildCrumbList(array $spec = array()) {
$crumb_list = array();
// On the home page, we don't have a DiffusionRequest.
if ($this->diffusionRequest) {
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
} else {
$drequest = null;
$repository = null;
}
if ($repository) {
$crumb_list[] = phutil_render_tag(
'a',
array(
'href' => '/diffusion/',
),
'Diffusion');
} else {
$crumb_list[] = 'Diffusion';
return $crumb_list;
}
$callsign = $repository->getCallsign();
$repository_name = phutil_escape_html($repository->getName()).' Repository';
if (empty($spec['commit'])) {
$branch_name = $drequest->getBranch();
if ($branch_name) {
$repository_name .= ' ('.phutil_escape_html($branch_name).')';
}
}
if (empty($spec['view']) && empty($spec['commit'])) {
$crumb_list[] = $repository_name;
return $crumb_list;
}
$crumb_list[] = phutil_render_tag(
'a',
array(
'href' => "/diffusion/{$callsign}/",
),
$repository_name);
$raw_commit = $drequest->getRawCommit();
if (isset($spec['commit'])) {
$crumb_list[] = "r{$callsign}{$raw_commit}";
return $crumb_list;
}
$view = $spec['view'];
$path = null;
if (isset($spec['path'])) {
$path = $drequest->getPath();
}
if ($raw_commit) {
$commit_link = DiffusionView::linkCommit(
$repository,
$raw_commit);
} else {
$commit_link = '';
}
switch ($view) {
case 'history':
$view_name = 'History';
break;
case 'browse':
$view_name = 'Browse';
break;
case 'change':
$view_name = 'Change';
$crumb_list[] = phutil_escape_html($path).' ('.$commit_link.')';
return $crumb_list;
}
$uri_params = array(
'action' => $view,
);
if (!strlen($path)) {
$crumb_list[] = $view_name;
} else {
$crumb_list[] = phutil_render_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
- 'path' => null,
+ 'path' => '',
) + $uri_params),
),
$view_name);
$path_parts = explode('/', $path);
do {
$last = array_pop($path_parts);
} while ($last == '');
$path_sections = array();
$thus_far = '';
foreach ($path_parts as $path_part) {
$thus_far .= $path_part.'/';
$path_sections[] = phutil_render_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'path' => $thus_far,
) + $uri_params),
),
phutil_escape_html($path_part));
}
$path_sections[] = phutil_escape_html($last);
$path_sections = '/'.implode('/', $path_sections);
$crumb_list[] = $path_sections;
}
$last_crumb = array_pop($crumb_list);
if ($raw_commit) {
$jump_link = phutil_render_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'commit' => null,
) + $uri_params),
),
'Jump to HEAD');
$last_crumb .= " @ {$commit_link} ({$jump_link})";
} else {
$last_crumb .= " @ HEAD";
}
$crumb_list[] = $last_crumb;
return $crumb_list;
}
}
diff --git a/src/applications/diffusion/controller/browse/DiffusionBrowseController.php b/src/applications/diffusion/controller/browse/DiffusionBrowseController.php
index 2b067458f2..64e18bb43e 100644
--- a/src/applications/diffusion/controller/browse/DiffusionBrowseController.php
+++ b/src/applications/diffusion/controller/browse/DiffusionBrowseController.php
@@ -1,88 +1,132 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DiffusionBrowseController extends DiffusionController {
public function processRequest() {
$drequest = $this->diffusionRequest;
$browse_query = DiffusionBrowseQuery::newFromDiffusionRequest($drequest);
$results = $browse_query->loadPaths();
$content = array();
$content[] = $this->buildCrumbs(
array(
'branch' => true,
'path' => true,
'view' => 'browse',
));
if (!$results) {
if ($browse_query->getReasonForEmptyResultSet() ==
DiffusionBrowseQuery::REASON_IS_FILE) {
$controller = new DiffusionBrowseFileController($this->getRequest());
$controller->setDiffusionRequest($drequest);
return $this->delegateToController($controller);
}
$empty_result = new DiffusionEmptyResultView();
$empty_result->setDiffusionRequest($drequest);
$empty_result->setBrowseQuery($browse_query);
$content[] = $empty_result;
} else {
+ $readme = null;
+
$phids = array();
foreach ($results as $result) {
$data = $result->getLastCommitData();
if ($data) {
if ($data->getCommitDetail('authorPHID')) {
$phids[$data->getCommitDetail('authorPHID')] = true;
}
}
+
+ $path = $result->getPath();
+ if (preg_match('/^readme(|\.txt|\.remarkup)$/i', $path)) {
+ $readme = $result;
+ }
}
- $phids = array_keys($phids);
+ $phids = array_keys($phids);
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
+ if ($readme) {
+ $readme_request = DiffusionRequest::newFromDictionary(
+ array(
+ 'repository' => $drequest->getRepository(),
+ 'commit' => $drequest->getStableCommitName(),
+ 'path' => $readme->getFullPath(),
+ ));
+
+ $content_query = DiffusionFileContentQuery::newFromDiffusionRequest(
+ $readme_request);
+ $content_query->loadFileContent();
+ $readme_content = $content_query->getRawData();
+
+ if (preg_match('/.txt$/', $readme->getPath())) {
+ $readme_content = phutil_escape_html($readme_content);
+ $readme_content = nl2br($readme_content);
+ } else {
+ // Markup extensionless files as remarkup so we get links and such.
+
+ $engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
+ $readme_content = $engine->markupText($readme_content);
+
+ $readme_content = phutil_render_tag(
+ 'div',
+ array(
+ 'class' => 'phabricator-remarkup',
+ ),
+ $readme_content);
+ }
+
+ $readme_panel = new AphrontPanelView();
+ $readme_panel->setHeader('README');
+ $readme_panel->appendChild($readme_content);
+
+ $content[] = $readme_panel;
+ }
+
$browse_table = new DiffusionBrowseTableView();
$browse_table->setDiffusionRequest($drequest);
$browse_table->setHandles($handles);
$browse_table->setPaths($results);
$browse_panel = new AphrontPanelView();
$browse_panel->appendChild($browse_table);
$content[] = $browse_panel;
}
$content[] = $this->buildOpenRevisions();
$nav = $this->buildSideNav('browse', false);
$nav->appendChild($content);
return $this->buildStandardPageResponse(
$nav,
array(
'title' => basename($drequest->getPath()),
));
}
}
diff --git a/src/applications/diffusion/controller/browse/__init__.php b/src/applications/diffusion/controller/browse/__init__.php
index 7d33550a58..1e19848118 100644
--- a/src/applications/diffusion/controller/browse/__init__.php
+++ b/src/applications/diffusion/controller/browse/__init__.php
@@ -1,20 +1,24 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
phutil_require_module('phabricator', 'applications/diffusion/controller/file');
phutil_require_module('phabricator', 'applications/diffusion/query/browse/base');
+phutil_require_module('phabricator', 'applications/diffusion/query/filecontent/base');
+phutil_require_module('phabricator', 'applications/diffusion/request/base');
phutil_require_module('phabricator', 'applications/diffusion/view/browsetable');
phutil_require_module('phabricator', 'applications/diffusion/view/emptyresult');
+phutil_require_module('phabricator', 'applications/markup/engine');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'view/layout/panel');
+phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('DiffusionBrowseController.php');
diff --git a/src/applications/diffusion/query/filecontent/base/DiffusionFileContentQuery.php b/src/applications/diffusion/query/filecontent/base/DiffusionFileContentQuery.php
index a159a634f5..17d7668237 100644
--- a/src/applications/diffusion/query/filecontent/base/DiffusionFileContentQuery.php
+++ b/src/applications/diffusion/query/filecontent/base/DiffusionFileContentQuery.php
@@ -1,150 +1,117 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-abstract class DiffusionFileContentQuery {
+abstract class DiffusionFileContentQuery extends DiffusionQuery {
- private $request;
private $needsBlame;
private $fileContent;
- final private function __construct() {
- // <private>
- }
-
final public static function newFromDiffusionRequest(
DiffusionRequest $request) {
-
- $repository = $request->getRepository();
-
- switch ($repository->getVersionControlSystem()) {
- case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
- $class = 'DiffusionGitFileContentQuery';
- break;
- case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
- $class = 'DiffusionMercurialFileContentQuery';
- break;
- case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
- $class = 'DiffusionSvnFileContentQuery';
- break;
- default:
- throw new Exception("Unsupported VCS!");
- }
-
- PhutilSymbolLoader::loadClass($class);
- $query = new $class();
-
- $query->request = $request;
-
- return $query;
+ return parent::newQueryObject(__CLASS__, $request);
}
public function getSupportsBlameOnBlame() {
return false;
}
public function getPrevRev($rev) {
// TODO: support git once the 'parent' info of a commit is saved
// to the database.
throw new Exception("Unsupported VCS!");
}
- final protected function getRequest() {
- return $this->request;
- }
-
final public function loadFileContent() {
$this->fileContent = $this->executeQuery();
}
- abstract protected function executeQuery();
-
final public function getRawData() {
return $this->fileContent->getCorpus();
}
final public function getBlameData() {
$raw_data = $this->getRawData();
$text_list = array();
$rev_list = array();
$blame_dict = array();
if (!$this->getNeedsBlame()) {
$text_list = explode("\n", rtrim($raw_data));
} else {
foreach (explode("\n", rtrim($raw_data)) as $k => $line) {
list($rev_id, $author, $text) = $this->tokenizeLine($line);
$text_list[$k] = $text;
$rev_list[$k] = $rev_id;
if (!isset($blame_dict[$rev_id]) &&
!isset($blame_dict[$rev_id]['author'] )) {
$blame_dict[$rev_id]['author'] = $author;
}
}
$repository = $this->getRequest()->getRepository();
$commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
'repositoryID = %d AND commitIdentifier IN (%Ls)', $repository->getID(),
array_unique($rev_list));
foreach ($commits as $commit) {
$blame_dict[$commit->getCommitIdentifier()]['epoch'] =
$commit->getEpoch();
}
$commits_data = array();
if ($commits) {
$commits_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere(
'commitID IN (%Ls)',
mpull($commits, 'getID'));
}
$phids = array();
foreach ($commits_data as $data) {
$phids[] = $data->getCommitDetail('authorPHID');
}
$handles = id(new PhabricatorObjectHandleData(array_unique($phids)))
->loadHandles();
foreach ($commits_data as $data) {
if ($data->getCommitDetail('authorPHID')) {
$commit_identifier =
$commits[$data->getCommitID()]->getCommitIdentifier();
$blame_dict[$commit_identifier]['handle'] =
$handles[$data->getCommitDetail('authorPHID')];
}
}
}
return array($text_list, $rev_list, $blame_dict);
}
abstract protected function tokenizeLine($line);
public function setNeedsBlame($needs_blame) {
$this->needsBlame = $needs_blame;
}
public function getNeedsBlame() {
return $this->needsBlame;
}
}
diff --git a/src/applications/diffusion/query/filecontent/base/__init__.php b/src/applications/diffusion/query/filecontent/base/__init__.php
index 19511645dc..cba7efae94 100644
--- a/src/applications/diffusion/query/filecontent/base/__init__.php
+++ b/src/applications/diffusion/query/filecontent/base/__init__.php
@@ -1,18 +1,17 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
+phutil_require_module('phabricator', 'applications/diffusion/query/base');
phutil_require_module('phabricator', 'applications/phid/handle/data');
-phutil_require_module('phabricator', 'applications/repository/constants/repositorytype');
phutil_require_module('phabricator', 'applications/repository/storage/commit');
phutil_require_module('phabricator', 'applications/repository/storage/commitdata');
-phutil_require_module('phutil', 'symbols');
phutil_require_module('phutil', 'utils');
phutil_require_source('DiffusionFileContentQuery.php');

File Metadata

Mime Type
text/x-diff
Expires
Fri, Nov 14, 5:59 AM (1 d, 5 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
336817
Default Alt Text
(19 KB)

Event Timeline