|
|
|
|
@@ -4,6 +4,9 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
|
|
|
|
|
|
|
|
|
private $corpusType = 'text';
|
|
|
|
|
|
|
|
|
|
private $lintCommit;
|
|
|
|
|
private $lintMessages;
|
|
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
@@ -45,6 +48,8 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
|
|
|
|
return $this->buildRawResponse($path, $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->loadLintMessages();
|
|
|
|
|
|
|
|
|
|
// Build the content of the file.
|
|
|
|
|
$corpus = $this->buildCorpus(
|
|
|
|
|
$selected,
|
|
|
|
|
@@ -119,6 +124,37 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function loadLintMessages() {
|
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
|
$branch = $drequest->loadBranch();
|
|
|
|
|
|
|
|
|
|
if (!$branch || !$branch->getLintCommit()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$file_history = DiffusionHistoryQuery::newFromDiffusionRequest(
|
|
|
|
|
$drequest)->setLimit(1)->loadHistory();
|
|
|
|
|
|
|
|
|
|
$lint_request = clone $drequest;
|
|
|
|
|
$lint_request->setCommit($branch->getLintCommit());
|
|
|
|
|
$lint_history = DiffusionHistoryQuery::newFromDiffusionRequest(
|
|
|
|
|
$lint_request)->setLimit(1)->loadHistory();
|
|
|
|
|
|
|
|
|
|
$this->lintCommit = '';
|
|
|
|
|
if (!$file_history || !$lint_history ||
|
|
|
|
|
reset($file_history)->getCommitIdentifier() !=
|
|
|
|
|
reset($lint_history)->getCommitIdentifier()) {
|
|
|
|
|
$this->lintCommit = $branch->getLintCommit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->lintMessages = queryfx_all(
|
|
|
|
|
id(new PhabricatorRepository())->establishConnection('r'),
|
|
|
|
|
'SELECT * FROM %T WHERE branchID = %d AND path = %s',
|
|
|
|
|
PhabricatorRepository::TABLE_LINTMESSAGE,
|
|
|
|
|
$branch->getID(),
|
|
|
|
|
'/'.$drequest->getPath());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function buildCorpus($selected,
|
|
|
|
|
DiffusionFileContentQuery $file_query,
|
|
|
|
|
$needs_blame,
|
|
|
|
|
@@ -267,6 +303,7 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
|
$base_uri = $this->getRequest()->getRequestURI();
|
|
|
|
|
|
|
|
|
|
$blame_on = ($selected == 'blame' || $selected == 'plainblame');
|
|
|
|
|
if ($blame_on) {
|
|
|
|
|
@@ -277,7 +314,7 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
|
|
|
|
|
|
|
|
|
$blame_button = $this->createViewAction(
|
|
|
|
|
$blame_text,
|
|
|
|
|
$toggle_blame[$selected],
|
|
|
|
|
$base_uri->alter('view', $toggle_blame[$selected]),
|
|
|
|
|
$user);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -289,13 +326,48 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
|
|
|
|
}
|
|
|
|
|
$highlight_button = $this->createViewAction(
|
|
|
|
|
$highlight_text,
|
|
|
|
|
$toggle_highlight[$selected],
|
|
|
|
|
$base_uri->alter('view', $toggle_highlight[$selected]),
|
|
|
|
|
$user);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$href = null;
|
|
|
|
|
if ($this->getRequest()->getBool('lint')) {
|
|
|
|
|
$lint_text = pht('Hide Lint Messages');
|
|
|
|
|
$href = $base_uri->alter('lint', null);
|
|
|
|
|
|
|
|
|
|
} else if ($this->lintCommit === null) {
|
|
|
|
|
$lint_text = pht('Lint not Available');
|
|
|
|
|
|
|
|
|
|
} else if ($this->lintCommit) {
|
|
|
|
|
$lint_text = pht(
|
|
|
|
|
'Switch for %d Lint Message(s)',
|
|
|
|
|
count($this->lintMessages));
|
|
|
|
|
$href = $this->getDiffusionRequest()->generateURI(array(
|
|
|
|
|
'action' => 'browse',
|
|
|
|
|
'commit' => $this->lintCommit,
|
|
|
|
|
))->alter('lint', true);
|
|
|
|
|
|
|
|
|
|
} else if (!$this->lintMessages) {
|
|
|
|
|
$lint_text = pht('0 Lint Messages');
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
$lint_text = pht('Show %d Lint Message(s)', count($this->lintMessages));
|
|
|
|
|
$href = $base_uri->alter('lint', true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$lint_button = $this->createViewAction(
|
|
|
|
|
$lint_text,
|
|
|
|
|
$href,
|
|
|
|
|
$user);
|
|
|
|
|
|
|
|
|
|
if (!$href) {
|
|
|
|
|
$lint_button->setDisabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$raw_button = $this->createViewAction(
|
|
|
|
|
pht('View Raw File'),
|
|
|
|
|
'raw',
|
|
|
|
|
$base_uri->alter('view', 'raw'),
|
|
|
|
|
$user,
|
|
|
|
|
'file');
|
|
|
|
|
|
|
|
|
|
@@ -305,23 +377,23 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
|
|
|
|
->setUser($user)
|
|
|
|
|
->addAction($blame_button)
|
|
|
|
|
->addAction($highlight_button)
|
|
|
|
|
->addAction($lint_button)
|
|
|
|
|
->addAction($raw_button)
|
|
|
|
|
->addAction($edit_button);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createViewAction(
|
|
|
|
|
$localized_text,
|
|
|
|
|
$view_mode,
|
|
|
|
|
$href,
|
|
|
|
|
$user,
|
|
|
|
|
$icon = null) {
|
|
|
|
|
|
|
|
|
|
$base_uri = $this->getRequest()->getRequestURI();
|
|
|
|
|
return id(new PhabricatorActionView())
|
|
|
|
|
->setName($localized_text)
|
|
|
|
|
->setIcon($icon)
|
|
|
|
|
->setUser($user)
|
|
|
|
|
->setRenderAsForm(true)
|
|
|
|
|
->setHref($base_uri->alter('view', $view_mode));
|
|
|
|
|
->setHref($href);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createEditAction() {
|
|
|
|
|
@@ -482,7 +554,33 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
|
|
|
|
|
|
|
|
|
Javelin::initBehavior('phabricator-oncopy', array());
|
|
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
|
$engine = null;
|
|
|
|
|
$inlines = array();
|
|
|
|
|
if ($this->getRequest()->getBool('lint') && $this->lintMessages) {
|
|
|
|
|
$engine = new PhabricatorMarkupEngine();
|
|
|
|
|
$engine->setViewer($user);
|
|
|
|
|
|
|
|
|
|
foreach ($this->lintMessages as $message) {
|
|
|
|
|
$inline = id(new PhabricatorAuditInlineComment())
|
|
|
|
|
->setSyntheticAuthor($message['code'].' ('.$message['name'].')')
|
|
|
|
|
->setLineNumber($message['line'])
|
|
|
|
|
->setContent($message['description']);
|
|
|
|
|
$inlines[$message['line']][] = $inline;
|
|
|
|
|
|
|
|
|
|
$engine->addObject(
|
|
|
|
|
$inline,
|
|
|
|
|
PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$engine->process();
|
|
|
|
|
require_celerity_resource('differential-changeset-view-css');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$rows = $this->renderInlines(
|
|
|
|
|
idx($inlines, 0, array()),
|
|
|
|
|
$needs_blame,
|
|
|
|
|
$engine);
|
|
|
|
|
|
|
|
|
|
foreach ($display as $line) {
|
|
|
|
|
|
|
|
|
|
$line_href = $drequest->generateURI(
|
|
|
|
|
@@ -654,11 +752,31 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
|
|
|
|
),
|
|
|
|
|
$blame.
|
|
|
|
|
$line_text);
|
|
|
|
|
|
|
|
|
|
$rows = array_merge($rows, $this->renderInlines(
|
|
|
|
|
idx($inlines, $line['line'], array()),
|
|
|
|
|
$needs_blame,
|
|
|
|
|
$engine));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $rows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function renderInlines(array $inlines, $needs_blame, $engine) {
|
|
|
|
|
$rows = array();
|
|
|
|
|
foreach ($inlines as $inline) {
|
|
|
|
|
$inline_view = id(new DifferentialInlineCommentView())
|
|
|
|
|
->setMarkupEngine($engine)
|
|
|
|
|
->setInlineComment($inline)
|
|
|
|
|
->render();
|
|
|
|
|
$rows[] =
|
|
|
|
|
'<tr class="inline">'.
|
|
|
|
|
str_repeat('<th></th>', ($needs_blame ? 5 : 1)).
|
|
|
|
|
'<td>'.$inline_view.'</td>'.
|
|
|
|
|
'</tr>';
|
|
|
|
|
}
|
|
|
|
|
return $rows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static function renderRevision(DiffusionRequest $drequest,
|
|
|
|
|
$revision) {
|
|
|
|
|
|