Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php b/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php
index 39d8e363b1..6b2632a658 100644
--- a/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php
+++ b/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php
@@ -1,155 +1,155 @@
<?php
/*
* Copyright 2011 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.
*/
class DiffusionBrowseFileController extends DiffusionController {
public function processRequest() {
// Build the view selection form.
$select_map = array(
'highlighted' => 'View as Highlighted Text',
//'blame' => 'View as Highlighted Text with Blame',
'plain' => 'View as Plain Text',
//'plainblame' => 'View as Plain Text with Blame',
);
$drequest = $this->getDiffusionRequest();
$request = $this->getRequest();
$selected = $request->getStr('view');
$select = '<select name="view">';
foreach ($select_map as $k => $v) {
$option = phutil_render_tag(
'option',
array(
'value' => $k,
'selected' => ($k == $selected) ? 'selected' : null,
),
phutil_escape_html($v));
$select .= $option;
}
$select .= '</select>';
$view_select_panel = new AphrontPanelView();
$view_select_form = phutil_render_tag(
'form',
array(
'action' => $request->getRequestURI(),
'method' => 'get',
'style' => 'display: inline',
),
$select.
'<button>view</button>');
$view_select_panel->appendChild($view_select_form);
$file_query = DiffusionFileContentQuery::newFromDiffusionRequest(
$this->diffusionRequest);
$file_content = $file_query->loadFileContent();
// Build the content of the file.
// TODO: image
// TODO: blame.
switch ($selected) {
case 'plain':
$style =
"margin: 1em 2em; width: 90%; height: 80em; font-family: monospace";
$corpus = phutil_render_tag(
'textarea',
array(
'style' => $style,
),
phutil_escape_html($file_content->getCorpus()));
break;
case 'highlighted':
default:
require_celerity_resource('syntax-highlighting-css');
require_celerity_resource('diffusion-source-css');
$path = $drequest->getPath();
$highlightEngine = new PhutilDefaultSyntaxHighlighterEngine();
$data = $highlightEngine->highlightSource($path,
$file_content->getCorpus());
$data = explode("\n", rtrim($data));
- $uri_path = $request->getPath();
+ $uri_path = $drequest->getUriPath();
$uri_rev = $drequest->getCommit();
$color = null;
$rows = array();
$n = 1;
foreach ($data as $k => $line) {
if ($n == $drequest->getLine()) {
$tr = '<tr style="background: #ffff00;">';
$targ = '<a id="scroll_target"></a>';
Javelin::initBehavior('diffusion-jump-to',
array('target' => 'scroll_target'));
} else {
$tr = '<tr>';
$targ = null;
}
$l = phutil_render_tag(
'a',
array(
'href' => $uri_path.';'.$uri_rev.'$'.$n,
),
$n);
$rows[] = $tr.'<th>'.$l.'</th><td>'.$targ.$line.'</td></tr>';
++$n;
}
$corpus_table = phutil_render_tag(
'table',
array(
'class' => "diffusion-source remarkup-code",
),
implode("\n", $rows));
$corpus = phutil_render_tag(
'div',
array(
'style' => 'padding: 0pt 2em;',
),
$corpus_table);
break;
}
// Render the page.
$content = array();
$content[] = $this->buildCrumbs(
array(
'branch' => true,
'path' => true,
'view' => 'browse',
));
$content[] = $view_select_panel;
$content[] = $corpus;
$nav = $this->buildSideNav('browse', true);
$nav->appendChild($content);
return $this->buildStandardPageResponse(
$nav,
array(
'title' => 'Browse',
));
}
}
diff --git a/src/applications/diffusion/request/base/DiffusionRequest.php b/src/applications/diffusion/request/base/DiffusionRequest.php
index eeadc6e739..c4b89144be 100644
--- a/src/applications/diffusion/request/base/DiffusionRequest.php
+++ b/src/applications/diffusion/request/base/DiffusionRequest.php
@@ -1,147 +1,151 @@
<?php
/*
* Copyright 2011 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.
*/
class DiffusionRequest {
protected $callsign;
protected $path;
protected $line;
protected $commit;
protected $branch;
protected $repository;
protected $repositoryCommit;
protected $repositoryCommitData;
final private function __construct() {
// <private>
}
final public static function newFromAphrontRequestDictionary(array $data) {
$vcs = null;
$repository = null;
$callsign = idx($data, 'callsign');
if ($callsign) {
$repository = id(new PhabricatorRepository())->loadOneWhere(
'callsign = %s',
$callsign);
if (!$repository) {
throw new Exception("No such repository '{$callsign}'.");
}
$vcs = $repository->getVersionControlSystem();
}
switch ($vcs) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$class = 'DiffusionGitRequest';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$class = 'DiffusionSvnRequest';
break;
default:
$class = 'DiffusionRequest';
break;
}
$object = new $class();
$object->callsign = $callsign;
$object->repository = $repository;
$object->line = idx($data, 'line');
$object->commit = idx($data, 'commit');
$object->path = idx($data, 'path');
$object->initializeFromAphrontRequestDictionary();
return $object;
}
protected function initializeFromAphrontRequestDictionary() {
}
protected function parsePath($path) {
$this->path = $path;
}
public function getRepository() {
return $this->repository;
}
public function getCallsign() {
return $this->callsign;
}
public function getPath() {
return $this->path;
}
+ public function getUriPath() {
+ return '/diffusion/'.$this->getCallsign().'/browse/'.$this->path;
+ }
+
public function getLine() {
return $this->line;
}
public function getCommit() {
return $this->commit;
}
public function getBranch() {
return $this->branch;
}
public function loadCommit() {
if (empty($this->repositoryCommit)) {
$repository = $this->getRepository();
$commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
'repositoryID = %d AND commitIdentifier = %s',
$repository->getID(),
$this->getCommit());
$this->repositoryCommit = $commit;
}
return $this->repositoryCommit;
}
public function loadCommitData() {
if (empty($this->repositoryCommitData)) {
$commit = $this->loadCommit();
$data = id(new PhabricatorRepositoryCommitData())->loadOneWhere(
'commitID = %d',
$commit->getID());
if (!$data) {
$data = new PhabricatorRepositoryCommitData();
$data->setCommitMessage('(This commit has not fully parsed yet.)');
}
$this->repositoryCommitData = $data;
}
return $this->repositoryCommitData;
}
final public function getRawCommit() {
return $this->commit;
}
public function getCommitURIComponent($commit) {
return $commit;
}
public function getBranchURIComponent($branch) {
return $branch;
}
}
diff --git a/src/applications/diffusion/request/git/DiffusionGitRequest.php b/src/applications/diffusion/request/git/DiffusionGitRequest.php
index b88e6cf2e3..56351b65eb 100644
--- a/src/applications/diffusion/request/git/DiffusionGitRequest.php
+++ b/src/applications/diffusion/request/git/DiffusionGitRequest.php
@@ -1,116 +1,121 @@
<?php
/*
* Copyright 2011 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.
*/
class DiffusionGitRequest extends DiffusionRequest {
protected function initializeFromAphrontRequestDictionary() {
parent::initializeFromAphrontRequestDictionary();
$path = $this->path;
$parts = explode('/', $path);
$branch = array_shift($parts);
$this->branch = $this->decodeBranchName($branch);
foreach ($parts as $key => $part) {
// Prevent any hyjinx since we're ultimately shipping this to the
// filesystem under a lot of git workflows.
if ($part == '..') {
unset($parts[$key]);
}
}
$this->path = implode('/', $parts);
if ($this->repository) {
$local_path = $this->repository->getDetail('local-path');
// TODO: This is not terribly efficient and does not produce terribly
// good error messages, but it seems better to put error handling code
// here than to try to do it in every query.
$branch = $this->getBranch();
execx(
'(cd %s && git rev-parse --verify %s)',
$local_path,
$branch);
if ($this->commit) {
list($commit) = execx(
'(cd %s && git rev-parse --verify %s)',
$local_path,
$this->commit);
// Beyond verifying them, expand commit short forms to full 40-character
// sha1s.
$this->commit = trim($commit);
list($contains) = execx(
'(cd %s && git branch --contains %s)',
$local_path,
$this->commit);
$contains = array_filter(explode("\n", $contains));
$found = false;
foreach ($contains as $containing_branch) {
$containing_branch = trim($containing_branch, "* \n");
if ($containing_branch == $branch) {
$found = true;
break;
}
}
if (!$found) {
throw new Exception(
"Commit does not exist on this branch!");
}
}
}
}
public function getBranch() {
if ($this->branch) {
return $this->branch;
}
if ($this->repository) {
return $this->repository->getDetail('default-branch', 'master');
}
throw new Exception("Unable to determine branch!");
}
+ public function getUriPath() {
+ return '/diffusion/'.$this->getCallsign().'/browse/'.
+ $this->branch.'/'.$this->path;
+ }
+
public function getCommit() {
if ($this->commit) {
return $this->commit;
}
return $this->getBranch();
}
public function getBranchURIComponent($branch) {
return $this->encodeBranchName($branch).'/';
}
private function decodeBranchName($branch) {
return str_replace(':', '/', $branch);
}
private function encodeBranchName($branch) {
return str_replace('/', ':', $branch);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Wed, Apr 30, 3:03 PM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
108737
Default Alt Text
(12 KB)

Event Timeline