1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +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
This commit is contained in:
epriestley 2011-05-11 21:46:29 -07:00
parent 63f6d807c5
commit 54154e4f48
15 changed files with 67 additions and 63 deletions

View file

@ -24,9 +24,17 @@ class DifferentialChangesetViewController extends DifferentialController {
$author_phid = $request->getUser()->getPHID(); $author_phid = $request->getUser()->getPHID();
$id = $request->getStr('id'); $rendering_reference = $request->getStr('ref');
$vs = $request->getInt('vs'); $parts = explode('/', $rendering_reference);
if (count($parts) == 2) {
list($id, $vs) = $parts;
} else {
$id = $parts[0];
$vs = 0;
}
$id = (int)$id;
$vs = (int)$vs;
$changeset = id(new DifferentialChangeset())->load($id); $changeset = id(new DifferentialChangeset())->load($id);
if (!$changeset) { if (!$changeset) {
@ -149,6 +157,7 @@ class DifferentialChangesetViewController extends DifferentialController {
$parser = new DifferentialChangesetParser(); $parser = new DifferentialChangesetParser();
$parser->setChangeset($changeset); $parser->setChangeset($changeset);
$parser->setRenderingReference($rendering_reference);
$parser->setRenderCacheKey($render_cache_key); $parser->setRenderCacheKey($render_cache_key);
$parser->setRightSideCommentMapping($right_source, $right_new); $parser->setRightSideCommentMapping($right_source, $right_new);
$parser->setLeftSideCommentMapping($left_source, $left_new); $parser->setLeftSideCommentMapping($left_source, $left_new);

View file

@ -58,7 +58,7 @@ class DifferentialRevisionViewController extends DifferentialController {
$diff_vs = null; $diff_vs = null;
} }
list($changesets, $vs_map) = list($changesets, $vs_map, $rendering_references) =
$this->loadChangesetsAndVsMap($diffs, $diff_vs, $target); $this->loadChangesetsAndVsMap($diffs, $diff_vs, $target);
$comments = $revision->loadComments(); $comments = $revision->loadComments();
@ -181,7 +181,7 @@ class DifferentialRevisionViewController extends DifferentialController {
$changeset_view->setEditable(true); $changeset_view->setEditable(true);
$changeset_view->setStandaloneViews(true); $changeset_view->setStandaloneViews(true);
$changeset_view->setRevision($revision); $changeset_view->setRevision($revision);
$changeset_view->setVsMap($vs_map); $changeset_view->setRenderingReferences($rendering_references);
$changeset_view->setWhitespace($whitespace); $changeset_view->setWhitespace($whitespace);
$diff_history = new DifferentialRevisionUpdateHistoryView(); $diff_history = new DifferentialRevisionUpdateHistoryView();
@ -604,6 +604,11 @@ class DifferentialRevisionViewController extends DifferentialController {
$changesets = idx($changeset_groups, $target->getID(), array()); $changesets = idx($changeset_groups, $target->getID(), array());
$changesets = mpull($changesets, null, 'getID'); $changesets = mpull($changesets, null, 'getID');
$refs = array();
foreach ($changesets as $changeset) {
$refs[$changeset->getID()] = $changeset->getID();
}
$vs_map = array(); $vs_map = array();
if ($diff_vs) { if ($diff_vs) {
$vs_changesets = idx($changeset_groups, $diff_vs, array()); $vs_changesets = idx($changeset_groups, $diff_vs, array());
@ -612,18 +617,23 @@ class DifferentialRevisionViewController extends DifferentialController {
$file = $changeset->getFilename(); $file = $changeset->getFilename();
if (isset($vs_changesets[$file])) { if (isset($vs_changesets[$file])) {
$vs_map[$changeset->getID()] = $vs_changesets[$file]->getID(); $vs_map[$changeset->getID()] = $vs_changesets[$file]->getID();
$refs[$changeset->getID()] =
$changeset->getID().'/'.$vs_changesets[$file]->getID();
unset($vs_changesets[$file]); unset($vs_changesets[$file]);
} else {
$refs[$changeset->getID()] = $changeset->getID();
} }
} }
foreach ($vs_changesets as $changeset) { foreach ($vs_changesets as $changeset) {
$changesets[$changeset->getID()] = $changeset; $changesets[$changeset->getID()] = $changeset;
$vs_map[$changeset->getID()] = -1; $vs_map[$changeset->getID()] = -1;
$refs[$changeset->getID()] = $changeset->getID().'/-1';
} }
} }
$changesets = msort($changesets, 'getSortKey'); $changesets = msort($changesets, 'getSortKey');
return array($changesets, $vs_map); return array($changesets, $vs_map, $refs);
} }
private function updateViewTime($user_phid, $revision_phid) { private function updateViewTime($user_phid, $revision_phid) {

View file

@ -28,7 +28,6 @@ class DifferentialChangesetParser {
protected $filename = null; protected $filename = null;
protected $filetype = null; protected $filetype = null;
protected $changesetID = null;
protected $missingOld = array(); protected $missingOld = array();
protected $missingNew = array(); protected $missingNew = array();
@ -52,6 +51,8 @@ class DifferentialChangesetParser {
private $rightSideChangesetID; private $rightSideChangesetID;
private $rightSideAttachesToNewFile; private $rightSideAttachesToNewFile;
private $renderingReference;
const CACHE_VERSION = 4; const CACHE_VERSION = 4;
const ATTR_GENERATED = 'attr:generated'; const ATTR_GENERATED = 'attr:generated';
@ -123,9 +124,7 @@ class DifferentialChangesetParser {
public function setChangeset($changeset) { public function setChangeset($changeset) {
$this->changeset = $changeset; $this->changeset = $changeset;
$this->setFilename($changeset->getFilename()); $this->setFilename($changeset->getFilename());
$this->setChangesetID($changeset->getID());
return $this; return $this;
} }
@ -135,8 +134,8 @@ class DifferentialChangesetParser {
return $this; return $this;
} }
public function setChangesetID($changeset_id) { public function setRenderingReference($ref) {
$this->changesetID = $changeset_id; $this->renderingReference = $ref;
return $this; return $this;
} }
@ -144,10 +143,6 @@ class DifferentialChangesetParser {
return $this->changeset; return $this->changeset;
} }
public function getChangesetID() {
return $this->changesetID;
}
public function setFilename($filename) { public function setFilename($filename) {
$this->filename = $filename; $this->filename = $filename;
if (strpos($filename, '.', 1) !== false) { if (strpos($filename, '.', 1) !== false) {
@ -968,7 +963,7 @@ EOSYNTHETIC;
if ($more) { if ($more) {
$end = $this->getLength(); $end = $this->getLength();
$reference = $this->getChangeset()->getRenderingReference(); $reference = $this->renderingReference;
$more = $more =
' '. ' '.
javelin_render_tag( javelin_render_tag(
@ -979,7 +974,7 @@ EOSYNTHETIC;
'class' => 'complete', 'class' => 'complete',
'href' => '#', 'href' => '#',
'meta' => array( 'meta' => array(
'id' => $reference, 'ref' => $reference,
'range' => "0-{$end}", 'range' => "0-{$end}",
), ),
), ),
@ -1073,7 +1068,7 @@ EOSYNTHETIC;
$gaps = array_reverse($gaps); $gaps = array_reverse($gaps);
$reference = $this->getChangeset()->getRenderingReference(); $reference = $this->renderingReference;
$left_id = $this->leftSideChangesetID; $left_id = $this->leftSideChangesetID;
$right_id = $this->rightSideChangesetID; $right_id = $this->rightSideChangesetID;
@ -1112,7 +1107,7 @@ EOSYNTHETIC;
'mustcapture' => true, 'mustcapture' => true,
'sigil' => 'show-more', 'sigil' => 'show-more',
'meta' => array( 'meta' => array(
'id' => $reference, 'ref' => $reference,
'range' => "{$top}-{$len}/{$top}-20", 'range' => "{$top}-{$len}/{$top}-20",
), ),
), ),
@ -1126,7 +1121,7 @@ EOSYNTHETIC;
'mustcapture' => true, 'mustcapture' => true,
'sigil' => 'show-more', 'sigil' => 'show-more',
'meta' => array( 'meta' => array(
'id' => $reference, 'ref' => $reference,
'range' => "{$top}-{$len}/{$top}-{$len}", 'range' => "{$top}-{$len}/{$top}-{$len}",
), ),
), ),
@ -1140,7 +1135,7 @@ EOSYNTHETIC;
'mustcapture' => true, 'mustcapture' => true,
'sigil' => 'show-more', 'sigil' => 'show-more',
'meta' => array( 'meta' => array(
'id' => $reference, 'ref' => $reference,
'range' => "{$top}-{$len}/{$end}-20", 'range' => "{$top}-{$len}/{$end}-20",
), ),
), ),

View file

@ -32,7 +32,6 @@ class DifferentialChangeset extends DifferentialDAO {
private $unsavedHunks = array(); private $unsavedHunks = array();
private $hunks; private $hunks;
private $renderingReference;
protected function getConfiguration() { protected function getConfiguration() {
return array( return array(
@ -76,18 +75,6 @@ class DifferentialChangeset extends DifferentialDAO {
return $name; return $name;
} }
public function setRenderingReference($rendering_reference) {
$this->renderingReference = $rendering_reference;
return $this;
}
public function getRenderingReference() {
if ($this->renderingReference) {
return $this->renderingReference;
}
return $this->getID();
}
public function addUnsavedHunk(DifferentialHunk $hunk) { public function addUnsavedHunk(DifferentialHunk $hunk) {
if ($this->hunks === null) { if ($this->hunks === null) {
$this->hunks = array(); $this->hunks = array();

View file

@ -22,7 +22,6 @@ class DifferentialChangesetListView extends AphrontView {
private $editable; private $editable;
private $revision; private $revision;
private $renderURI = '/differential/changeset/'; private $renderURI = '/differential/changeset/';
private $vsMap = array();
private $whitespace; private $whitespace;
private $standaloneViews; private $standaloneViews;
@ -46,8 +45,8 @@ class DifferentialChangesetListView extends AphrontView {
return $this; return $this;
} }
public function setVsMap(array $vs_map) { public function setRenderingReferences(array $references) {
$this->vsMap = $vs_map; $this->references = $references;
return $this; return $this;
} }
@ -64,7 +63,6 @@ class DifferentialChangesetListView extends AphrontView {
public function render() { public function render() {
require_celerity_resource('differential-changeset-view-css'); require_celerity_resource('differential-changeset-view-css');
$vs_map = $this->vsMap;
$changesets = $this->changesets; $changesets = $this->changesets;
$output = array(); $output = array();
@ -75,22 +73,15 @@ class DifferentialChangesetListView extends AphrontView {
if (!$this->editable) { if (!$this->editable) {
$class .= ' differential-changeset-noneditable'; $class .= ' differential-changeset-noneditable';
} }
$id = $changeset->getID();
if ($id) {
$vs_id = idx($vs_map, $id);
} else {
$vs_id = null;
}
$ref = $changeset->getRenderingReference(); $ref = $this->references[$key];
$detail_button = null; $detail_button = null;
if ($this->standaloneViews) { if ($this->standaloneViews) {
$detail_uri = new PhutilURI($this->renderURI); $detail_uri = new PhutilURI($this->renderURI);
$detail_uri->setQueryParams( $detail_uri->setQueryParams(
array( array(
'id' => $ref, 'ref' => $ref,
'vs' => $vs_id,
'whitespace' => $this->whitespace, 'whitespace' => $this->whitespace,
)); ));
@ -118,9 +109,7 @@ class DifferentialChangesetListView extends AphrontView {
'<div class="differential-loading">Loading...</div>')); '<div class="differential-loading">Loading...</div>'));
$output[] = $detail->render(); $output[] = $detail->render();
$mapping[$uniq_id] = array( $mapping[$uniq_id] = $ref;
$ref,
$vs_id);
} }
Javelin::initBehavior('differential-populate', array( Javelin::initBehavior('differential-populate', array(
@ -131,6 +120,7 @@ class DifferentialChangesetListView extends AphrontView {
Javelin::initBehavior('differential-show-more', array( Javelin::initBehavior('differential-show-more', array(
'uri' => $this->renderURI, 'uri' => $this->renderURI,
'whitespace' => $this->whitespace,
)); ));
Javelin::initBehavior('differential-comment-jump', array()); Javelin::initBehavior('differential-comment-jump', array());

View file

@ -13,7 +13,6 @@ phutil_require_module('phabricator', 'view/base');
phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'parser/uri'); phutil_require_module('phutil', 'parser/uri');
phutil_require_module('phutil', 'utils');
phutil_require_source('DifferentialChangesetListView.php'); phutil_require_source('DifferentialChangesetListView.php');

View file

@ -32,9 +32,18 @@ class DiffusionChangeController extends DiffusionController {
} }
$changeset_view = new DifferentialChangesetListView(); $changeset_view = new DifferentialChangesetListView();
$changeset_view->setChangesets(array($changeset)); $changeset_view->setChangesets(
array(
0 => $changeset,
));
$changeset_view->setRenderingReferences(
array(
0 => $diff_query->getRenderingReference(),
));
$changeset_view->setRenderURI( $changeset_view->setRenderURI(
'/diffusion/'.$drequest->getRepository()->getCallsign().'/diff/'); '/diffusion/'.$drequest->getRepository()->getCallsign().'/diff/');
$changeset_view->setWhitespace(
DifferentialChangesetParser::WHITESPACE_SHOW_ALL);
$content[] = $this->buildCrumbs( $content[] = $this->buildCrumbs(
array( array(

View file

@ -7,6 +7,7 @@
phutil_require_module('phabricator', 'aphront/response/404'); phutil_require_module('phabricator', 'aphront/response/404');
phutil_require_module('phabricator', 'applications/differential/parser/changeset');
phutil_require_module('phabricator', 'applications/differential/view/changesetlistview'); phutil_require_module('phabricator', 'applications/differential/view/changesetlistview');
phutil_require_module('phabricator', 'applications/diffusion/controller/base'); phutil_require_module('phabricator', 'applications/diffusion/controller/base');
phutil_require_module('phabricator', 'applications/diffusion/query/diff/base'); phutil_require_module('phabricator', 'applications/diffusion/query/diff/base');

View file

@ -146,6 +146,7 @@ class DiffusionCommitController extends DiffusionController {
throw new Exception("Unknown VCS."); throw new Exception("Unknown VCS.");
} }
$references = array();
foreach ($changesets as $key => $changeset) { foreach ($changesets as $key => $changeset) {
$file_type = $changeset->getFileType(); $file_type = $changeset->getFileType();
if ($file_type == DifferentialChangeType::FILE_DIRECTORY) { if ($file_type == DifferentialChangeType::FILE_DIRECTORY) {
@ -160,11 +161,12 @@ class DiffusionCommitController extends DiffusionController {
$filename = $changeset->getFilename(); $filename = $changeset->getFilename();
$commit = $drequest->getCommit(); $commit = $drequest->getCommit();
$reference = "{$branch}{$filename};{$commit}"; $reference = "{$branch}{$filename};{$commit}";
$changeset->setRenderingReference($reference); $references[$key] = $reference;
} }
$change_list = new DifferentialChangesetListView(); $change_list = new DifferentialChangesetListView();
$change_list->setChangesets($changesets); $change_list->setChangesets($changesets);
$change_list->setRenderingReferences($references);
$change_list->setRenderURI('/diffusion/'.$callsign.'/diff/'); $change_list->setRenderURI('/diffusion/'.$callsign.'/diff/');
// TODO: This is pretty awkward, unify the CSS between Diffusion and // TODO: This is pretty awkward, unify the CSS between Diffusion and

View file

@ -20,8 +20,8 @@ class DiffusionDiffController extends DiffusionController {
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
$request = $this->getRequest(); $request = $this->getRequest();
if ($request->getStr('id')) { if ($request->getStr('ref')) {
$parts = explode(';', $request->getStr('id')); $parts = explode(';', $request->getStr('ref'));
$data['path'] = idx($parts, 0); $data['path'] = idx($parts, 0);
$data['commit'] = idx($parts, 1); $data['commit'] = idx($parts, 1);
} }
@ -43,6 +43,7 @@ class DiffusionDiffController extends DiffusionController {
$parser = new DifferentialChangesetParser(); $parser = new DifferentialChangesetParser();
$parser->setChangeset($changeset); $parser->setChangeset($changeset);
$parser->setRenderingReference($diff_query->getRenderingReference());
$parser->setWhitespaceMode( $parser->setWhitespaceMode(
DifferentialChangesetParser::WHITESPACE_SHOW_ALL); DifferentialChangesetParser::WHITESPACE_SHOW_ALL);

View file

@ -27,7 +27,7 @@ class DiffusionLastModifiedController extends DiffusionController {
list($commit, $commit_data) = $modified_query->loadLastModification(); list($commit, $commit_data) = $modified_query->loadLastModification();
$phids = array(); $phids = array();
if ($commit_data->getCommitDetail('authorPHID')) { if ($commit_data && $commit_data->getCommitDetail('authorPHID')) {
$phids = array($commit_data->getCommitDetail('authorPHID')); $phids = array($commit_data->getCommitDetail('authorPHID'));
} }

View file

@ -19,6 +19,7 @@
abstract class DiffusionDiffQuery { abstract class DiffusionDiffQuery {
private $request; private $request;
protected $renderingReference;
final private function __construct() { final private function __construct() {
// <private> // <private>
@ -52,6 +53,10 @@ abstract class DiffusionDiffQuery {
return $this->request; return $this->request;
} }
final public function getRenderingReference() {
return $this->renderingReference;
}
final public function loadChangeset() { final public function loadChangeset() {
return $this->executeQuery(); return $this->executeQuery();
} }

View file

@ -59,13 +59,11 @@ final class DiffusionGitDiffQuery extends DiffusionDiffQuery {
$changesets = $diff->getChangesets(); $changesets = $diff->getChangesets();
$changeset = reset($changesets); $changeset = reset($changesets);
$id = $this->renderingReference =
$drequest->getBranchURIComponent($drequest->getBranch()). $drequest->getBranchURIComponent($drequest->getBranch()).
$drequest->getPath().';'. $drequest->getPath().';'.
$drequest->getCommit(); $drequest->getCommit();
$changeset->setID($id);
return $changeset; return $changeset;
} }

View file

@ -125,8 +125,7 @@ final class DiffusionSvnDiffQuery extends DiffusionDiffQuery {
$changesets = $diff->getChangesets(); $changesets = $diff->getChangesets();
$changeset = reset($changesets); $changeset = reset($changesets);
$reference = $drequest->getPath().';'.$drequest->getCommit(); $this->renderingReference = $drequest->getPath().';'.$drequest->getCommit();
$changeset->setRenderingReference($reference);
return $changeset; return $changeset;
} }

View file

@ -15,8 +15,7 @@ JX.behavior('differential-populate', function(config) {
for (var k in config.registry) { for (var k in config.registry) {
new JX.Request(config.uri, JX.bind(null, onresponse, k)) new JX.Request(config.uri, JX.bind(null, onresponse, k))
.setData({ .setData({
id: config.registry[k][0], ref : config.registry[k],
vs: config.registry[k][1],
whitespace: config.whitespace whitespace: config.whitespace
}) })
.send(); .send();