1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-06 21:01:02 +01:00

Add a link from Differential to Diffusion

Summary:
Provide an easy way to jump to Diffusion from Differential if we have
the data we need to connect them.

Test Plan: Tested menu in linked and unlinked diffs. Used menu item.

Reviewers: btrahan, jungejason

Reviewed By: btrahan

CC: aran, epriestley, btrahan

Maniphest Tasks: T309

Differential Revision: https://secure.phabricator.com/D1326
This commit is contained in:
epriestley 2012-01-05 14:41:11 -08:00
parent da3a972400
commit 1903bb80bb
7 changed files with 99 additions and 44 deletions

View file

@ -472,15 +472,16 @@ celerity_register_resource_map(array(
), ),
'javelin-behavior-differential-dropdown-menus' => 'javelin-behavior-differential-dropdown-menus' =>
array( array(
'uri' => '/res/08e751ee/rsrc/js/application/differential/behavior-dropdown-menus.js', 'uri' => '/res/c5abbb83/rsrc/js/application/differential/behavior-dropdown-menus.js',
'type' => 'js', 'type' => 'js',
'requires' => 'requires' =>
array( array(
0 => 'javelin-behavior', 0 => 'javelin-behavior',
1 => 'javelin-dom', 1 => 'javelin-dom',
2 => 'javelin-stratcom', 2 => 'javelin-util',
3 => 'phabricator-dropdown-menu', 3 => 'javelin-stratcom',
4 => 'phabricator-menu-item', 4 => 'phabricator-dropdown-menu',
5 => 'phabricator-menu-item',
), ),
'disk' => '/rsrc/js/application/differential/behavior-dropdown-menus.js', 'disk' => '/rsrc/js/application/differential/behavior-dropdown-menus.js',
), ),
@ -1418,7 +1419,7 @@ celerity_register_resource_map(array(
), ),
'phabricator-menu-item' => 'phabricator-menu-item' =>
array( array(
'uri' => '/res/8a9be282/rsrc/js/application/core/DropdownMenuItem.js', 'uri' => '/res/cfd0a620/rsrc/js/application/core/DropdownMenuItem.js',
'type' => 'js', 'type' => 'js',
'requires' => 'requires' =>
array( array(

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -187,7 +187,18 @@ class DifferentialRevisionViewController extends DifferentialController {
'whitespace', 'whitespace',
DifferentialChangesetParser::WHITESPACE_IGNORE_ALL); DifferentialChangesetParser::WHITESPACE_IGNORE_ALL);
$symbol_indexes = $this->buildSymbolIndexes($target, $visible_changesets); $arc_project = $target->loadArcanistProject();
if ($arc_project) {
$symbol_indexes = $this->buildSymbolIndexes(
$target,
$arc_project,
$visible_changesets);
$repository = $arc_project->loadRepository();
} else {
$symbol_indexes = array();
$repository = null;
}
$revision_detail->setActions($actions); $revision_detail->setActions($actions);
$revision_detail->setUser($user); $revision_detail->setUser($user);
@ -205,8 +216,12 @@ class DifferentialRevisionViewController extends DifferentialController {
$changeset_view->setEditable(!$viewer_is_anonymous); $changeset_view->setEditable(!$viewer_is_anonymous);
$changeset_view->setStandaloneViews(true); $changeset_view->setStandaloneViews(true);
$changeset_view->setRevision($revision); $changeset_view->setRevision($revision);
$changeset_view->setDiff($target);
$changeset_view->setRenderingReferences($rendering_references); $changeset_view->setRenderingReferences($rendering_references);
$changeset_view->setWhitespace($whitespace); $changeset_view->setWhitespace($whitespace);
if ($repository) {
$changeset_view->setRepository($repository, $target);
}
$changeset_view->setSymbolIndexes($symbol_indexes); $changeset_view->setSymbolIndexes($symbol_indexes);
$diff_history = new DifferentialRevisionUpdateHistoryView(); $diff_history = new DifferentialRevisionUpdateHistoryView();
@ -597,21 +612,18 @@ class DifferentialRevisionViewController extends DifferentialController {
private function buildSymbolIndexes( private function buildSymbolIndexes(
DifferentialDiff $target, DifferentialDiff $target,
PhabricatorRepositoryArcanistProject $arc_project,
array $visible_changesets) { array $visible_changesets) {
$engine = PhabricatorSyntaxHighlighter::newEngine(); $engine = PhabricatorSyntaxHighlighter::newEngine();
$symbol_indexes = array();
$arc_project = $target->loadArcanistProject();
if (!$arc_project) {
return array();
}
$langs = $arc_project->getSymbolIndexLanguages(); $langs = $arc_project->getSymbolIndexLanguages();
if (!$langs) { if (!$langs) {
return array(); return array();
} }
$symbol_indexes = array();
$project_phids = array_merge( $project_phids = array_merge(
array($arc_project->getPHID()), array($arc_project->getPHID()),
nonempty($arc_project->getSymbolIndexProjects(), array())); nonempty($arc_project->getSymbolIndexProjects(), array()));

View file

@ -25,6 +25,8 @@ class DifferentialChangesetListView extends AphrontView {
private $whitespace; private $whitespace;
private $standaloneViews; private $standaloneViews;
private $symbolIndexes = array(); private $symbolIndexes = array();
private $repository;
private $diff;
public function setChangesets($changesets) { public function setChangesets($changesets) {
$this->changesets = $changesets; $this->changesets = $changesets;
@ -46,6 +48,16 @@ class DifferentialChangesetListView extends AphrontView {
return $this; return $this;
} }
public function setRepository(PhabricatorRepository $repository) {
$this->repository = $repository;
return $this;
}
public function setDiff(DifferentialDiff $diff) {
$this->diff = $diff;
return $this;
}
public function setRenderingReferences(array $references) { public function setRenderingReferences(array $references) {
$this->references = $references; $this->references = $references;
return $this; return $this;
@ -79,6 +91,7 @@ class DifferentialChangesetListView extends AphrontView {
$output = array(); $output = array();
$mapping = array(); $mapping = array();
$repository = $this->repository;
foreach ($changesets as $key => $changeset) { foreach ($changesets as $key => $changeset) {
$file = $changeset->getFilename(); $file = $changeset->getFilename();
$class = 'differential-changeset'; $class = 'differential-changeset';
@ -97,14 +110,21 @@ class DifferentialChangesetListView extends AphrontView {
'whitespace' => $this->whitespace, 'whitespace' => $this->whitespace,
)); ));
$diffusion_uri = null;
if ($repository) {
$diffusion_uri = $repository->getDiffusionBrowseURIForPath(
$changeset->getAbsoluteRepositoryPath($this->diff, $repository));
}
$detail_button = javelin_render_tag( $detail_button = javelin_render_tag(
'a', 'a',
array( array(
'class' => 'button small grey', 'class' => 'button small grey',
'meta' => array( 'meta' => array(
'detailURI' => (string)$detail_uri, 'detailURI' => (string)$detail_uri,
'leftURI' => (string)$detail_uri->alter('view', 'old'), 'leftURI' => (string)$detail_uri->alter('view', 'old'),
'rightURI' => (string)$detail_uri->alter('view', 'new'), 'rightURI' => (string)$detail_uri->alter('view', 'new'),
'diffusionURI' => $diffusion_uri,
), ),
'href' => $detail_uri, 'href' => $detail_uri,
'target' => '_blank', 'target' => '_blank',

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -156,10 +156,14 @@ final class DiffusionSvnBrowseQuery extends DiffusionBrowseQuery {
$repository->getID(), $repository->getID(),
$loadable_commits); $loadable_commits);
$commits = mpull($commits, null, 'getCommitIdentifier'); $commits = mpull($commits, null, 'getCommitIdentifier');
$commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere( if ($commits) {
'commitID in (%Ld)', $commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere(
mpull($commits, 'getID')); 'commitID in (%Ld)',
$commit_data = mpull($commit_data, null, 'getCommitID'); mpull($commits, 'getID'));
$commit_data = mpull($commit_data, null, 'getCommitID');
} else {
$commit_data = array();
}
} }
$path_normal = DiffusionPathIDQuery::normalizePath($path); $path_normal = DiffusionPathIDQuery::normalizePath($path);

View file

@ -57,6 +57,22 @@ class PhabricatorRepository extends PhabricatorRepositoryDAO {
return $this; return $this;
} }
public function getDiffusionBrowseURIForPath($path) {
switch ($this->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$branch = '/'.$this->getDetail('default-branch');
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$branch = null;
break;
default:
throw new Exception("Unknown VCS.");
}
return '/diffusion/'.$this->getCallsign().'/browse'.$branch.$path;
}
public static function newPhutilURIFromGitURI($raw_uri) { public static function newPhutilURIFromGitURI($raw_uri) {
// If there's no protocol (git implicit SSH) reformat the URI to be a // If there's no protocol (git implicit SSH) reformat the URI to be a
// normal URI. These git URIs look like "user@domain.com:path" instead of // normal URI. These git URIs look like "user@domain.com:path" instead of

View file

@ -17,12 +17,20 @@ JX.install('PhabricatorMenuItem', {
_action : null, _action : null,
render : function() { render : function() {
return JX.$N('a', { href : '#', meta : { item : this } }, this._name); if (this.getDisabled()) {
return JX.$N('span', this._name);
} else {
return JX.$N('a', { href : '#', meta : { item : this } }, this._name);
}
}, },
select : function() { select : function() {
this._action(); this._action();
} }
},
properties : {
disabled : false
} }
}); });

View file

@ -2,6 +2,7 @@
* @provides javelin-behavior-differential-dropdown-menus * @provides javelin-behavior-differential-dropdown-menus
* @requires javelin-behavior * @requires javelin-behavior
* javelin-dom * javelin-dom
* javelin-util
* javelin-stratcom * javelin-stratcom
* phabricator-dropdown-menu * phabricator-dropdown-menu
* phabricator-menu-item * phabricator-menu-item
@ -9,40 +10,33 @@
JX.behavior('differential-dropdown-menus', function(config) { JX.behavior('differential-dropdown-menus', function(config) {
function standalone(button) {
return function() {
window.open(JX.Stratcom.getData(button).detailURI);
}
}
function left_file(button) {
return function() {
window.open(JX.Stratcom.getData(button).leftURI);
}
}
function right_file(button) {
return function() {
window.open(JX.Stratcom.getData(button).rightURI);
}
}
var buttons = JX.DOM.scry(window.document, 'a', 'differential-view-options'); var buttons = JX.DOM.scry(window.document, 'a', 'differential-view-options');
for (var ii = 0; ii < buttons.length; ii++) { for (var ii = 0; ii < buttons.length; ii++) {
var button = buttons[ii]; var data = JX.Stratcom.getData(buttons[ii]);
var diffusion_item = new JX.PhabricatorMenuItem(
'Browse in Diffusion',
JX.bind(null, window.open, data.diffusionURI))
if (!data.diffusionURI) {
diffusion_item.setDisabled(true);
}
new JX.PhabricatorDropdownMenu(buttons[ii]) new JX.PhabricatorDropdownMenu(buttons[ii])
.addItem(diffusion_item)
.addItem( .addItem(
new JX.PhabricatorMenuItem( new JX.PhabricatorMenuItem(
'View Standalone', 'View Standalone',
standalone(button))) JX.bind(null, window.open, data.detailURI)))
.addItem( .addItem(
new JX.PhabricatorMenuItem( new JX.PhabricatorMenuItem(
'Show Raw File (Left)', 'Show Raw File (Left)',
left_file(button))) JX.bind(null, window.open, data.leftURI)))
.addItem( .addItem(
new JX.PhabricatorMenuItem( new JX.PhabricatorMenuItem(
'Show Raw File (Right)', 'Show Raw File (Right)',
right_file(button))); JX.bind(null, window.open, data.rightURI)));
} }
}); });