1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-04 20:01:00 +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' =>
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',
'requires' =>
array(
0 => 'javelin-behavior',
1 => 'javelin-dom',
2 => 'javelin-stratcom',
3 => 'phabricator-dropdown-menu',
4 => 'phabricator-menu-item',
2 => 'javelin-util',
3 => 'javelin-stratcom',
4 => 'phabricator-dropdown-menu',
5 => 'phabricator-menu-item',
),
'disk' => '/rsrc/js/application/differential/behavior-dropdown-menus.js',
),
@ -1418,7 +1419,7 @@ celerity_register_resource_map(array(
),
'phabricator-menu-item' =>
array(
'uri' => '/res/8a9be282/rsrc/js/application/core/DropdownMenuItem.js',
'uri' => '/res/cfd0a620/rsrc/js/application/core/DropdownMenuItem.js',
'type' => 'js',
'requires' =>
array(

View file

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

View file

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

View file

@ -1,7 +1,7 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (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(),
$loadable_commits);
$commits = mpull($commits, null, 'getCommitIdentifier');
$commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere(
'commitID in (%Ld)',
mpull($commits, 'getID'));
$commit_data = mpull($commit_data, null, 'getCommitID');
if ($commits) {
$commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere(
'commitID in (%Ld)',
mpull($commits, 'getID'));
$commit_data = mpull($commit_data, null, 'getCommitID');
} else {
$commit_data = array();
}
}
$path_normal = DiffusionPathIDQuery::normalizePath($path);

View file

@ -57,6 +57,22 @@ class PhabricatorRepository extends PhabricatorRepositoryDAO {
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) {
// 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

View file

@ -17,12 +17,20 @@ JX.install('PhabricatorMenuItem', {
_action : null,
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() {
this._action();
}
},
properties : {
disabled : false
}
});

View file

@ -2,6 +2,7 @@
* @provides javelin-behavior-differential-dropdown-menus
* @requires javelin-behavior
* javelin-dom
* javelin-util
* javelin-stratcom
* phabricator-dropdown-menu
* phabricator-menu-item
@ -9,40 +10,33 @@
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');
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])
.addItem(diffusion_item)
.addItem(
new JX.PhabricatorMenuItem(
'View Standalone',
standalone(button)))
JX.bind(null, window.open, data.detailURI)))
.addItem(
new JX.PhabricatorMenuItem(
'Show Raw File (Left)',
left_file(button)))
JX.bind(null, window.open, data.leftURI)))
.addItem(
new JX.PhabricatorMenuItem(
'Show Raw File (Right)',
right_file(button)));
JX.bind(null, window.open, data.rightURI)));
}
});