2011-01-25 00:52:35 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-04 18:10:37 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-01-25 00:52:35 +01:00
|
|
|
*
|
|
|
|
* 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 DifferentialChangesetViewController extends DifferentialController {
|
|
|
|
|
|
|
|
|
2011-10-24 21:27:16 +02:00
|
|
|
public function shouldRequireLogin() {
|
|
|
|
return !$this->allowsAnonymousAccess();
|
|
|
|
}
|
|
|
|
|
2011-01-25 00:52:35 +01:00
|
|
|
public function processRequest() {
|
2011-02-01 05:38:13 +01:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$author_phid = $request->getUser()->getPHID();
|
2011-02-01 05:38:13 +01:00
|
|
|
|
Move "Rendering References" to the DifferentialChangesetParser level
Summary:
Separates changeset IDs from rendering. Now each changeset has a "rendering
reference" which is basically a description of what the ajax endpoint should
render. For Differential, it's in the form "id/vs". For Diffusion,
"branch/path;commit".
I believe this fixes pretty much all of the bugs related to "show more" breaking
in various obscure ways, although I never got a great repro for T153.
Test Plan:
Clicked "show more" in diffusion change and commit views and differential diff,
diff-of-diff, standalone-diff, standalone-diff-of-diff views. Verified refs and
'whitespace' were always sent correctly.
Made inline comments on diffs and diffs-of-diffs. Used "Reply".
Reviewed By: tuomaspelkonen
Reviewers: tuomaspelkonen, jungejason, aran
CC: aran, tuomaspelkonen, epriestley
Differential Revision: 274
2011-05-12 06:46:29 +02:00
|
|
|
$rendering_reference = $request->getStr('ref');
|
|
|
|
$parts = explode('/', $rendering_reference);
|
|
|
|
if (count($parts) == 2) {
|
|
|
|
list($id, $vs) = $parts;
|
|
|
|
} else {
|
|
|
|
$id = $parts[0];
|
|
|
|
$vs = 0;
|
|
|
|
}
|
2011-02-04 00:41:58 +01:00
|
|
|
|
Move "Rendering References" to the DifferentialChangesetParser level
Summary:
Separates changeset IDs from rendering. Now each changeset has a "rendering
reference" which is basically a description of what the ajax endpoint should
render. For Differential, it's in the form "id/vs". For Diffusion,
"branch/path;commit".
I believe this fixes pretty much all of the bugs related to "show more" breaking
in various obscure ways, although I never got a great repro for T153.
Test Plan:
Clicked "show more" in diffusion change and commit views and differential diff,
diff-of-diff, standalone-diff, standalone-diff-of-diff views. Verified refs and
'whitespace' were always sent correctly.
Made inline comments on diffs and diffs-of-diffs. Used "Reply".
Reviewed By: tuomaspelkonen
Reviewers: tuomaspelkonen, jungejason, aran
CC: aran, tuomaspelkonen, epriestley
Differential Revision: 274
2011-05-12 06:46:29 +02:00
|
|
|
$id = (int)$id;
|
|
|
|
$vs = (int)$vs;
|
2011-02-04 00:41:58 +01:00
|
|
|
|
2011-02-01 05:38:13 +01:00
|
|
|
$changeset = id(new DifferentialChangeset())->load($id);
|
2011-01-25 00:52:35 +01:00
|
|
|
if (!$changeset) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2011-05-06 21:58:53 +02:00
|
|
|
$view = $request->getStr('view');
|
|
|
|
if ($view) {
|
|
|
|
$changeset->attachHunks($changeset->loadHunks());
|
|
|
|
switch ($view) {
|
|
|
|
case 'new':
|
|
|
|
return $this->buildRawFileResponse($changeset->makeNewFile());
|
|
|
|
case 'old':
|
|
|
|
return $this->buildRawFileResponse($changeset->makeOldFile());
|
|
|
|
default:
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-04 00:41:58 +01:00
|
|
|
if ($vs && ($vs != -1)) {
|
|
|
|
$vs_changeset = id(new DifferentialChangeset())->load($vs);
|
|
|
|
if (!$vs_changeset) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$vs) {
|
|
|
|
$right = $changeset;
|
|
|
|
$left = null;
|
|
|
|
|
|
|
|
$right_source = $right->getID();
|
|
|
|
$right_new = true;
|
|
|
|
$left_source = $right->getID();
|
|
|
|
$left_new = false;
|
2011-05-05 16:08:10 +02:00
|
|
|
|
|
|
|
$render_cache_key = $right->getID();
|
2011-02-04 00:41:58 +01:00
|
|
|
} else if ($vs == -1) {
|
|
|
|
$right = null;
|
|
|
|
$left = $changeset;
|
|
|
|
|
|
|
|
$right_source = $left->getID();
|
|
|
|
$right_new = false;
|
|
|
|
$left_source = $left->getID();
|
|
|
|
$left_new = true;
|
2011-05-05 16:08:10 +02:00
|
|
|
|
|
|
|
$render_cache_key = null;
|
2011-02-04 00:41:58 +01:00
|
|
|
} else {
|
|
|
|
$right = $changeset;
|
|
|
|
$left = $vs_changeset;
|
|
|
|
|
|
|
|
$right_source = $right->getID();
|
|
|
|
$right_new = true;
|
|
|
|
$left_source = $left->getID();
|
|
|
|
$left_new = true;
|
2011-05-05 16:08:10 +02:00
|
|
|
|
|
|
|
$render_cache_key = null;
|
2011-02-04 00:41:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($left) {
|
|
|
|
$left->attachHunks($left->loadHunks());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($right) {
|
|
|
|
$right->attachHunks($right->loadHunks());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($left) {
|
|
|
|
|
|
|
|
$left_data = $left->makeNewFile();
|
|
|
|
if ($right) {
|
|
|
|
$right_data = $right->makeNewFile();
|
|
|
|
} else {
|
|
|
|
$right_data = $left->makeOldFile();
|
|
|
|
}
|
|
|
|
|
2011-07-17 20:06:02 +02:00
|
|
|
$engine = new PhabricatorDifferenceEngine();
|
|
|
|
$synthetic = $engine->generateChangesetFromFileContent(
|
|
|
|
$left_data,
|
|
|
|
$right_data);
|
2011-02-04 00:41:58 +01:00
|
|
|
|
|
|
|
$choice = nonempty($left, $right);
|
2011-07-17 20:06:02 +02:00
|
|
|
$choice->attachHunks($synthetic->getHunks());
|
2011-02-04 00:41:58 +01:00
|
|
|
|
|
|
|
$changeset = $choice;
|
|
|
|
}
|
2011-01-25 00:52:35 +01:00
|
|
|
|
2011-07-17 20:06:02 +02:00
|
|
|
$spec = $request->getStr('range');
|
|
|
|
list($range_s, $range_e, $mask) =
|
|
|
|
DifferentialChangesetParser::parseRangeSpecification($spec);
|
2011-02-01 05:38:13 +01:00
|
|
|
|
2011-01-25 00:52:35 +01:00
|
|
|
$parser = new DifferentialChangesetParser();
|
|
|
|
$parser->setChangeset($changeset);
|
Move "Rendering References" to the DifferentialChangesetParser level
Summary:
Separates changeset IDs from rendering. Now each changeset has a "rendering
reference" which is basically a description of what the ajax endpoint should
render. For Differential, it's in the form "id/vs". For Diffusion,
"branch/path;commit".
I believe this fixes pretty much all of the bugs related to "show more" breaking
in various obscure ways, although I never got a great repro for T153.
Test Plan:
Clicked "show more" in diffusion change and commit views and differential diff,
diff-of-diff, standalone-diff, standalone-diff-of-diff views. Verified refs and
'whitespace' were always sent correctly.
Made inline comments on diffs and diffs-of-diffs. Used "Reply".
Reviewed By: tuomaspelkonen
Reviewers: tuomaspelkonen, jungejason, aran
CC: aran, tuomaspelkonen, epriestley
Differential Revision: 274
2011-05-12 06:46:29 +02:00
|
|
|
$parser->setRenderingReference($rendering_reference);
|
2011-05-05 16:08:10 +02:00
|
|
|
$parser->setRenderCacheKey($render_cache_key);
|
2011-02-04 00:41:58 +01:00
|
|
|
$parser->setRightSideCommentMapping($right_source, $right_new);
|
|
|
|
$parser->setLeftSideCommentMapping($left_source, $left_new);
|
2011-04-18 22:38:54 +02:00
|
|
|
$parser->setWhitespaceMode($request->getStr('whitespace'));
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-05-09 06:22:25 +02:00
|
|
|
// Load both left-side and right-side inline comments.
|
|
|
|
$inlines = $this->loadInlineComments(
|
|
|
|
array($left_source, $right_source),
|
|
|
|
$author_phid);
|
|
|
|
|
2012-01-04 18:10:37 +01:00
|
|
|
if ($left_new) {
|
|
|
|
$inlines = array_merge(
|
|
|
|
$inlines,
|
|
|
|
$this->buildLintInlineComments($left));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($right_new) {
|
|
|
|
$inlines = array_merge(
|
|
|
|
$inlines,
|
|
|
|
$this->buildLintInlineComments($right));
|
|
|
|
}
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$phids = array();
|
|
|
|
foreach ($inlines as $inline) {
|
|
|
|
$parser->parseInlineComment($inline);
|
2012-01-04 18:10:37 +01:00
|
|
|
if ($inline->getAuthorPHID()) {
|
|
|
|
$phids[$inline->getAuthorPHID()] = true;
|
|
|
|
}
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|
|
|
|
$phids = array_keys($phids);
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$handles = id(new PhabricatorObjectHandleData($phids))
|
|
|
|
->loadHandles();
|
|
|
|
$parser->setHandles($handles);
|
2011-02-02 22:48:52 +01:00
|
|
|
|
Generalize the markup engine factory
Summary:
This thing services every app but it lives inside Differential right now. Pull
it out, and separate the factory interfaces per-application.
This will let us accommodate changes we need to make for Phriction to support
wiki linking.
Test Plan: Tested remarkup in differential, diffusion, maniphest, people,
slowvote.
Reviewed By: hsb
Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran
CC: aran, hsb
Differential Revision: 646
2011-07-12 00:58:32 +02:00
|
|
|
$engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
|
2011-02-02 01:42:36 +01:00
|
|
|
$parser->setMarkupEngine($engine);
|
2011-01-25 00:52:35 +01:00
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
if ($request->isAjax()) {
|
|
|
|
// TODO: This is sort of lazy, the effect is just to not render "Edit"
|
|
|
|
// links on the "standalone view".
|
|
|
|
$parser->setUser($request->getUser());
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = $parser->render($range_s, $range_e, $mask);
|
2011-01-25 00:52:35 +01:00
|
|
|
|
2011-01-25 20:57:47 +01:00
|
|
|
if ($request->isAjax()) {
|
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent($output);
|
|
|
|
}
|
|
|
|
|
2011-02-01 05:38:13 +01:00
|
|
|
Javelin::initBehavior('differential-show-more', array(
|
|
|
|
'uri' => '/differential/changeset/',
|
2011-05-11 02:36:06 +02:00
|
|
|
'whitespace' => $request->getStr('whitespace'),
|
2011-02-01 05:38:13 +01:00
|
|
|
));
|
|
|
|
|
2011-05-11 21:25:29 +02:00
|
|
|
Javelin::initBehavior('differential-comment-jump', array());
|
|
|
|
|
2011-01-25 20:57:47 +01:00
|
|
|
$detail = new DifferentialChangesetDetailView();
|
|
|
|
$detail->setChangeset($changeset);
|
|
|
|
$detail->appendChild($output);
|
2011-05-06 21:58:53 +02:00
|
|
|
|
2011-04-15 23:25:23 +02:00
|
|
|
$detail->setRevisionID($request->getInt('revision_id'));
|
2011-01-25 20:57:47 +01:00
|
|
|
|
2011-01-25 00:52:35 +01:00
|
|
|
$output =
|
2011-06-08 21:39:03 +02:00
|
|
|
id(new DifferentialPrimaryPaneView())
|
|
|
|
->setLineWidthFromChangesets(array($changeset))
|
|
|
|
->appendChild(
|
|
|
|
'<div class="differential-review-stage" '.
|
|
|
|
'id="differential-review-stage">'.
|
|
|
|
$detail->render().
|
|
|
|
'</div>');
|
2011-01-25 00:52:35 +01:00
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
array(
|
|
|
|
$output
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => 'Changeset View',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-05-09 06:22:25 +02:00
|
|
|
private function loadInlineComments(array $changeset_ids, $author_phid) {
|
|
|
|
$changeset_ids = array_unique(array_filter($changeset_ids));
|
|
|
|
if (!$changeset_ids) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
return id(new DifferentialInlineComment())->loadAllWhere(
|
2011-05-09 06:22:25 +02:00
|
|
|
'changesetID IN (%Ld) AND (commentID IS NOT NULL OR authorPHID = %s)',
|
|
|
|
$changeset_ids,
|
2011-02-02 01:42:36 +01:00
|
|
|
$author_phid);
|
|
|
|
}
|
|
|
|
|
2011-05-06 21:58:53 +02:00
|
|
|
private function buildRawFileResponse($text) {
|
|
|
|
return id(new AphrontFileResponse())
|
|
|
|
->setMimeType('text/plain')
|
|
|
|
->setContent($text);
|
|
|
|
}
|
2011-02-02 01:42:36 +01:00
|
|
|
|
2012-01-04 18:10:37 +01:00
|
|
|
private function buildLintInlineComments($changeset) {
|
|
|
|
$lint = id(new DifferentialDiffProperty())->loadOneWhere(
|
|
|
|
'diffID = %d AND name = %s',
|
|
|
|
$changeset->getDiffID(),
|
|
|
|
'arc:lint');
|
|
|
|
if (!$lint) {
|
2012-01-05 18:11:49 +01:00
|
|
|
return array();
|
2012-01-04 18:10:37 +01:00
|
|
|
}
|
|
|
|
$lint = $lint->getData();
|
|
|
|
|
|
|
|
$inlines = array();
|
|
|
|
foreach ($lint as $msg) {
|
|
|
|
if ($msg['path'] != $changeset->getFileName()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$inline = new DifferentialInlineComment();
|
|
|
|
$inline->setChangesetID($changeset->getID());
|
|
|
|
$inline->setIsNewFile(true);
|
|
|
|
$inline->setSyntheticAuthor('Lint: '.$msg['name']);
|
|
|
|
$inline->setLineNumber($msg['line']);
|
|
|
|
$inline->setLineLength(0);
|
|
|
|
|
|
|
|
$inline->setContent('%%%'.$msg['description'].'%%%');
|
|
|
|
|
|
|
|
$inlines[] = $inline;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $inlines;
|
|
|
|
}
|
|
|
|
|
2011-01-25 00:52:35 +01:00
|
|
|
}
|