1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Fix inline comment links for non-visible comments

Summary: Ref T2222. Restore this funky is-visible / inline-is-elsewhere logic.

Test Plan: Updated a revision, saw all the inlines render properly when looking at various diffs and versus-diffs. Clicked inline links.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2222

Differential Revision: https://secure.phabricator.com/D8224
This commit is contained in:
epriestley 2014-02-13 16:03:23 -08:00
parent 9afe52de51
commit 7374a0a4d4
3 changed files with 73 additions and 4 deletions

View file

@ -260,6 +260,8 @@ final class DifferentialRevisionViewController extends DifferentialController {
$comment_view = $this->buildTransactions( $comment_view = $this->buildTransactions(
$revision, $revision,
$diff_vs ? $diffs[$diff_vs] : $target,
$target,
$all_changesets); $all_changesets);
$wrap_id = celerity_generate_unique_node_id(); $wrap_id = celerity_generate_unique_node_id();
@ -931,6 +933,8 @@ final class DifferentialRevisionViewController extends DifferentialController {
private function buildTransactions( private function buildTransactions(
DifferentialRevision $revision, DifferentialRevision $revision,
DifferentialDiff $left_diff,
DifferentialDiff $right_diff,
array $changesets) { array $changesets) {
$viewer = $this->getRequest()->getUser(); $viewer = $this->getRequest()->getUser();
@ -947,6 +951,9 @@ final class DifferentialRevisionViewController extends DifferentialController {
->setUser($viewer) ->setUser($viewer)
->setObjectPHID($revision->getPHID()) ->setObjectPHID($revision->getPHID())
->setChangesets($changesets) ->setChangesets($changesets)
->setRevision($revision)
->setLeftDiff($left_diff)
->setRightDiff($right_diff)
->setTransactions($xactions); ->setTransactions($xactions);
// TODO: Make this work and restore edit links. We need to copy // TODO: Make this work and restore edit links. We need to copy

View file

@ -701,10 +701,18 @@ final class DifferentialRevisionEditor extends PhabricatorEditor {
$template = id(new DifferentialComment()) $template = id(new DifferentialComment())
->setAuthorPHID($this->getActorPHID()) ->setAuthorPHID($this->getActorPHID())
->setRevision($this->revision); ->setRevision($this->revision);
if ($this->contentSource) { if ($this->contentSource) {
$template->setContentSource($this->contentSource); $content_source = $this->contentSource;
} else {
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array());
} }
$template->setContentSource($content_source);
// Write the "update active diff" transaction. // Write the "update active diff" transaction.
id(clone $template) id(clone $template)
->setAction(DifferentialAction::ACTION_UPDATE) ->setAction(DifferentialAction::ACTION_UPDATE)

View file

@ -4,6 +4,36 @@ final class DifferentialTransactionView
extends PhabricatorApplicationTransactionView { extends PhabricatorApplicationTransactionView {
private $changesets; private $changesets;
private $revision;
private $rightDiff;
private $leftDiff;
public function setLeftDiff(DifferentialDiff $left_diff) {
$this->leftDiff = $left_diff;
return $this;
}
public function getLeftDiff() {
return $this->leftDiff;
}
public function setRightDiff(DifferentialDiff $right_diff) {
$this->rightDiff = $right_diff;
return $this;
}
public function getRightDiff() {
return $this->rightDiff;
}
public function setRevision(DifferentialRevision $revision) {
$this->revision = $revision;
return $this;
}
public function getRevision() {
return $this->revision;
}
public function setChangesets(array $changesets) { public function setChangesets(array $changesets) {
assert_instances_of($changesets, 'DifferentialChangeset'); assert_instances_of($changesets, 'DifferentialChangeset');
@ -100,8 +130,8 @@ final class DifferentialTransactionView
$by_line = array(); $by_line = array();
foreach ($group as $inline) { foreach ($group as $inline) {
$by_line[] = array( $by_line[] = array(
'line' => $inline->getComment()->getLineNumber().','. 'line' => ((int)$inline->getComment()->getLineNumber() << 16) +
$inline->getComment()->getLineLength(), ((int)$inline->getComment()->getLineLength()),
'inline' => $inline, 'inline' => $inline,
); );
} }
@ -119,7 +149,31 @@ final class DifferentialTransactionView
'content' => parent::renderTransactionContent($inline), 'content' => parent::renderTransactionContent($inline),
); );
// TODO: Fix the where/href stuff for nonlocal inlines. $changeset_diff_id = $changeset->getDiffID();
if ($comment->getIsNewFile()) {
$visible_diff_id = $this->getRightDiff()->getID();
} else {
$visible_diff_id = $this->getLeftDiff()->getID();
}
// TODO: We still get one edge case wrong here, when we have a
// versus diff and the file didn't exist in the old version. The
// comment is visible because we show the left side of the target
// diff when there's no corresponding file in the versus diff, but
// we incorrectly link it off-page.
$is_visible = ($changeset_diff_id == $visible_diff_id);
if (!$is_visible) {
$item['where'] = pht('(On Diff #%d)', $changeset_diff_id);
$revision_id = $this->getRevision()->getID();
$comment_id = $comment->getID();
$item['href'] =
"/D".$revision_id.
"?id=".$changeset_diff_id.
"#inline-".$comment_id;
}
$items[] = $item; $items[] = $item;
} }