mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Improve Diffusion behavior for externals
Summary: - Feature request from Airtime that I missed in the feedback notes, came up yesterday. - Identify git submodules as "FILE_SUBMODULE", not "FILE_NORMAL". - Link git submodules to an external resolver endpoint, which tries to find commits in tracked repositories. - Identify git symlinks as "FILE_SYMLINK", not "FILE_NORMAL". - Add folder, file, symlink and externals icons. Test Plan: - externals/javelin is now identified as a submoudule and links to Javelin, not identified as a file and links to error. - bin/phd is now identified as a symlink. - Interfaces have pretty icons. Reviewers: btrahan, cpiro, ddfisher, keebuhm, allenjohnashton Reviewed By: btrahan CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D1975
This commit is contained in:
parent
460a462164
commit
c0aac8267d
16 changed files with 335 additions and 10 deletions
|
@ -275,6 +275,15 @@ celerity_register_resource_map(array(
|
|||
),
|
||||
'disk' => '/rsrc/css/application/diffusion/commit-view.css',
|
||||
),
|
||||
'diffusion-icons-css' =>
|
||||
array(
|
||||
'uri' => '/res/2633e4b7/rsrc/css/application/diffusion/diffusion-icons.css',
|
||||
'type' => 'css',
|
||||
'requires' =>
|
||||
array(
|
||||
),
|
||||
'disk' => '/rsrc/css/application/diffusion/diffusion-icons.css',
|
||||
),
|
||||
'diffusion-source-css' =>
|
||||
array(
|
||||
'uri' => '/res/5f5ac1d6/rsrc/css/application/diffusion/diffusion-source.css',
|
||||
|
|
|
@ -295,6 +295,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionDiffController' => 'applications/diffusion/controller/diff',
|
||||
'DiffusionDiffQuery' => 'applications/diffusion/query/diff/base',
|
||||
'DiffusionEmptyResultView' => 'applications/diffusion/view/emptyresult',
|
||||
'DiffusionExternalController' => 'applications/diffusion/controller/external',
|
||||
'DiffusionFileContent' => 'applications/diffusion/data/filecontent',
|
||||
'DiffusionFileContentQuery' => 'applications/diffusion/query/filecontent/base',
|
||||
'DiffusionGitBranchQuery' => 'applications/diffusion/query/branch/git',
|
||||
|
@ -1156,6 +1157,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionController' => 'PhabricatorController',
|
||||
'DiffusionDiffController' => 'DiffusionController',
|
||||
'DiffusionEmptyResultView' => 'DiffusionView',
|
||||
'DiffusionExternalController' => 'DiffusionController',
|
||||
'DiffusionGitBranchQuery' => 'DiffusionBranchQuery',
|
||||
'DiffusionGitBranchQueryTestCase' => 'PhabricatorTestCase',
|
||||
'DiffusionGitBrowseQuery' => 'DiffusionBrowseQuery',
|
||||
|
|
|
@ -263,6 +263,7 @@ class AphrontDefaultApplicationConfiguration
|
|||
),
|
||||
),
|
||||
'symbol/(?P<name>[^/]+)/' => 'DiffusionSymbolController',
|
||||
'external/' => 'DiffusionExternalController',
|
||||
),
|
||||
|
||||
'/daemon/' => array(
|
||||
|
|
149
src/applications/diffusion/controller/external/DiffusionExternalController.php
vendored
Normal file
149
src/applications/diffusion/controller/external/DiffusionExternalController.php
vendored
Normal file
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
final class DiffusionExternalController extends DiffusionController {
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
// Don't build a DiffusionRequest.
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
|
||||
$uri = $request->getStr('uri');
|
||||
$id = $request->getStr('id');
|
||||
|
||||
$repositories = id(new PhabricatorRepository())->loadAll();
|
||||
|
||||
if ($uri) {
|
||||
$uri_path = id(new PhutilURI($uri))->getPath();
|
||||
$matches = array();
|
||||
|
||||
// Try to figure out which tracked repository this external lives in by
|
||||
// comparing repository metadata. We look for an exact match, but accept
|
||||
// a partial match.
|
||||
|
||||
foreach ($repositories as $key => $repository) {
|
||||
$remote_uri = new PhutilURI($repository->getRemoteURI());
|
||||
if ($remote_uri->getPath() == $uri_path) {
|
||||
$matches[$key] = 1;
|
||||
}
|
||||
if ($repository->getPublicRemoteURI() == $uri) {
|
||||
$matches[$key] = 2;
|
||||
}
|
||||
if ($repository->getRemoteURI() == $uri) {
|
||||
$matches[$key] = 3;
|
||||
}
|
||||
}
|
||||
|
||||
arsort($matches);
|
||||
reset($matches);
|
||||
$best_match = key($matches);
|
||||
|
||||
if ($best_match) {
|
||||
$repository = $repositories[$best_match];
|
||||
$redirect = DiffusionRequest::generateDiffusionURI(
|
||||
array(
|
||||
'action' => 'browse',
|
||||
'callsign' => $repository->getCallsign(),
|
||||
'commit' => $id,
|
||||
));
|
||||
return id(new AphrontRedirectResponse())->setURI($redirect);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This is a rare query but does a table scan, add a key?
|
||||
|
||||
$commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
|
||||
'commitIdentifier = %s',
|
||||
$id);
|
||||
|
||||
if (empty($commits)) {
|
||||
$desc = null;
|
||||
if ($uri) {
|
||||
$desc = phutil_escape_html($uri).', at ';
|
||||
}
|
||||
$desc .= phutil_escape_html($id);
|
||||
|
||||
$content = id(new AphrontErrorView())
|
||||
->setTitle('Unknown External')
|
||||
->setSeverity(AphrontErrorView::SEVERITY_WARNING)
|
||||
->appendChild(
|
||||
"<p>This external ({$desc}) does not appear in any tracked ".
|
||||
"repository. It may exist in an untracked repository that ".
|
||||
"Diffusion does not know about.</p>");
|
||||
} else if (count($commits) == 1) {
|
||||
$commit = head($commits);
|
||||
$redirect = DiffusionRequest::generateDiffusionURI(
|
||||
array(
|
||||
'action' => 'browse',
|
||||
'callsign' => $repositories[$commit->getRepositoryID()]
|
||||
->getCallsign(),
|
||||
'commit' => $commit->getCommitIdentifier(),
|
||||
));
|
||||
return id(new AphrontRedirectResponse())->setURI($redirect);
|
||||
} else {
|
||||
|
||||
$rows = array();
|
||||
foreach ($commits as $commit) {
|
||||
$repo = $repositories[$commit->getRepositoryID()];
|
||||
$href = DiffusionRequest::generateDiffusionURI(
|
||||
array(
|
||||
'action' => 'browse',
|
||||
'callsign' => $repo->getCallsign(),
|
||||
'commit' => $commit->getCommitIdentifier(),
|
||||
));
|
||||
$rows[] = array(
|
||||
phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $href,
|
||||
),
|
||||
phutil_escape_html(
|
||||
'r'.$repo->getCallsign().$commit->getCommitIdentifier())),
|
||||
phutil_escape_html($commit->loadCommitData()->getSummary()),
|
||||
);
|
||||
}
|
||||
|
||||
$table = new AphrontTableView($rows);
|
||||
$table->setHeaders(
|
||||
array(
|
||||
'Commit',
|
||||
'Description',
|
||||
));
|
||||
$table->setColumnClasses(
|
||||
array(
|
||||
'pri',
|
||||
'wide',
|
||||
));
|
||||
|
||||
$content = new AphrontPanelView();
|
||||
$content->setHeader('Multiple Matching Commits');
|
||||
$content->setCaption(
|
||||
'This external reference matches multiple known commits.');
|
||||
$content->appendChild($table);
|
||||
}
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
$content,
|
||||
array(
|
||||
'title' => 'Unresolvable External',
|
||||
));
|
||||
}
|
||||
|
||||
}
|
23
src/applications/diffusion/controller/external/__init__.php
vendored
Normal file
23
src/applications/diffusion/controller/external/__init__.php
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/request/base');
|
||||
phutil_require_module('phabricator', 'applications/repository/storage/commit');
|
||||
phutil_require_module('phabricator', 'applications/repository/storage/repository');
|
||||
phutil_require_module('phabricator', 'view/control/table');
|
||||
phutil_require_module('phabricator', 'view/form/error');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'parser/uri');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('DiffusionExternalController.php');
|
|
@ -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.
|
||||
|
@ -18,14 +18,25 @@
|
|||
|
||||
final class DiffusionRepositoryPath {
|
||||
|
||||
private $fullPath;
|
||||
private $path;
|
||||
private $hash;
|
||||
private $fileType;
|
||||
private $fileSize;
|
||||
private $externalURI;
|
||||
|
||||
private $lastModifiedCommit;
|
||||
private $lastCommitData;
|
||||
|
||||
public function setFullPath($full_path) {
|
||||
$this->fullPath = $full_path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFullPath() {
|
||||
return $this->fullPath;
|
||||
}
|
||||
|
||||
final public function setPath($path) {
|
||||
$this->path = $path;
|
||||
return $this;
|
||||
|
@ -82,4 +93,13 @@ final class DiffusionRepositoryPath {
|
|||
return $this->fileSize;
|
||||
}
|
||||
|
||||
final public function setExternalURI($external_uri) {
|
||||
$this->externalURI = $external_uri;
|
||||
return $this;
|
||||
}
|
||||
|
||||
final public function getExternalURI() {
|
||||
return $this->externalURI;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -74,18 +74,32 @@ final class DiffusionGitBrowseQuery extends DiffusionBrowseQuery {
|
|||
$commit,
|
||||
$path);
|
||||
|
||||
$submodules = array();
|
||||
|
||||
$results = array();
|
||||
foreach (explode("\0", rtrim($stdout)) as $line) {
|
||||
|
||||
// NOTE: Limit to 5 components so we parse filenames with spaces in them
|
||||
// correctly.
|
||||
list($mode, $type, $hash, $size, $name) = preg_split('/\s+/', $line, 5);
|
||||
if ($type == 'tree') {
|
||||
$file_type = DifferentialChangeType::FILE_DIRECTORY;
|
||||
} else {
|
||||
$file_type = DifferentialChangeType::FILE_NORMAL;
|
||||
}
|
||||
|
||||
$result = new DiffusionRepositoryPath();
|
||||
|
||||
if ($type == 'tree') {
|
||||
$file_type = DifferentialChangeType::FILE_DIRECTORY;
|
||||
} else if ($type == 'commit') {
|
||||
$file_type = DifferentialChangeType::FILE_SUBMODULE;
|
||||
$submodules[] = $result;
|
||||
} else {
|
||||
$mode = intval($mode, 8);
|
||||
if (($mode & 0120000) == 0120000) {
|
||||
$file_type = DifferentialChangeType::FILE_SYMLINK;
|
||||
} else {
|
||||
$file_type = DifferentialChangeType::FILE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
$result->setFullPath($path.$name);
|
||||
$result->setPath($name);
|
||||
$result->setHash($hash);
|
||||
$result->setFileType($file_type);
|
||||
|
@ -94,6 +108,30 @@ final class DiffusionGitBrowseQuery extends DiffusionBrowseQuery {
|
|||
$results[] = $result;
|
||||
}
|
||||
|
||||
// If we identified submodules, lookup the module info at this commit to
|
||||
// find their source URIs.
|
||||
|
||||
if ($submodules) {
|
||||
list($module_info) = $repository->execxLocalCommand(
|
||||
'show %s:.gitmodules',
|
||||
$commit);
|
||||
$module_info = parse_ini_string(
|
||||
$module_info,
|
||||
$process_sections = true,
|
||||
$scanner_mode = INI_SCANNER_RAW);
|
||||
|
||||
foreach ($submodules as $path) {
|
||||
foreach ($module_info as $section) {
|
||||
if (empty($section['path']) || empty($section['url'])) {
|
||||
continue;
|
||||
}
|
||||
if ($section['path'] == $path->getFullPath()) {
|
||||
$path->setExternalURI($section['url']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
|
|
@ -377,6 +377,10 @@ abstract class DiffusionRequest {
|
|||
case 'branch':
|
||||
$uri = "/diffusion/{$callsign}repository/{$path}";
|
||||
break;
|
||||
case 'external':
|
||||
$commit = ltrim($commit, ';');
|
||||
$uri = "/diffusion/external/{$commit}/";
|
||||
break;
|
||||
case 'rendering-ref':
|
||||
// This isn't a real URI per se, it's passed as a query parameter to
|
||||
// the ajax changeset stuff but then we parse it back out as though
|
||||
|
|
|
@ -79,7 +79,9 @@ abstract class DiffusionView extends AphrontView {
|
|||
'path' => $path,
|
||||
));
|
||||
|
||||
if (isset($details['text'])) {
|
||||
if (isset($details['html'])) {
|
||||
$text = $details['html'];
|
||||
} else if (isset($details['text'])) {
|
||||
$text = phutil_escape_html($details['text']);
|
||||
} else {
|
||||
$text = 'Browse';
|
||||
|
@ -93,6 +95,22 @@ abstract class DiffusionView extends AphrontView {
|
|||
$text);
|
||||
}
|
||||
|
||||
final public function linkExternal($hash, $uri, $text) {
|
||||
$href = id(new PhutilURI('/diffusion/external/'))
|
||||
->setQueryParams(
|
||||
array(
|
||||
'uri' => $uri,
|
||||
'id' => $hash,
|
||||
));
|
||||
|
||||
return phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $href,
|
||||
),
|
||||
$text);
|
||||
}
|
||||
|
||||
final public static function linkCommit($repository, $commit) {
|
||||
|
||||
switch ($repository->getVersionControlSystem()) {
|
||||
|
|
|
@ -11,6 +11,8 @@ phutil_require_module('phabricator', 'applications/repository/constants/reposito
|
|||
phutil_require_module('phabricator', 'view/base');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'parser/uri');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('DiffusionView.php');
|
||||
|
|
|
@ -86,22 +86,41 @@ final class DiffusionBrowseTableView extends DiffusionView {
|
|||
$rows = array();
|
||||
foreach ($this->paths as $path) {
|
||||
|
||||
if ($path->getFileType() == DifferentialChangeType::FILE_DIRECTORY) {
|
||||
$file_type = $path->getFileType();
|
||||
if ($file_type == DifferentialChangeType::FILE_DIRECTORY) {
|
||||
$browse_text = $path->getPath().'/';
|
||||
$dir_slash = '/';
|
||||
|
||||
$browse_link = '<strong>'.$this->linkBrowse(
|
||||
$base_path.$path->getPath().$dir_slash,
|
||||
array(
|
||||
'text' => $browse_text,
|
||||
'html' => $this->renderPathIcon(
|
||||
'dir',
|
||||
$browse_text),
|
||||
)).'</strong>';
|
||||
} else if ($file_type == DifferentialChangeType::FILE_SUBMODULE) {
|
||||
$browse_text = $path->getPath().'/';
|
||||
$browse_link =
|
||||
'<strong>'.
|
||||
$this->linkExternal(
|
||||
$path->getHash(),
|
||||
$path->getExternalURI(),
|
||||
$this->renderPathIcon(
|
||||
'ext',
|
||||
$browse_text)).
|
||||
'</strong>';
|
||||
} else {
|
||||
if ($file_type == DifferentialChangeType::FILE_SYMLINK) {
|
||||
$type = 'link';
|
||||
} else {
|
||||
$type = 'file';
|
||||
}
|
||||
$browse_text = $path->getPath();
|
||||
$dir_slash = null;
|
||||
$browse_link = $this->linkBrowse(
|
||||
$base_path.$path->getPath().$dir_slash,
|
||||
array(
|
||||
'text' => $browse_text,
|
||||
'html' => $this->renderPathIcon($type, $browse_text),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -172,4 +191,16 @@ final class DiffusionBrowseTableView extends DiffusionView {
|
|||
return $view->render();
|
||||
}
|
||||
|
||||
private function renderPathIcon($type, $text) {
|
||||
|
||||
require_celerity_resource('diffusion-icons-css');
|
||||
|
||||
return phutil_render_tag(
|
||||
'span',
|
||||
array(
|
||||
'class' => 'diffusion-path-icon diffusion-path-icon-'.$type,
|
||||
),
|
||||
phutil_escape_html($text));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
28
webroot/rsrc/css/application/diffusion/diffusion-icons.css
Normal file
28
webroot/rsrc/css/application/diffusion/diffusion-icons.css
Normal file
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* @provides diffusion-icons-css
|
||||
*/
|
||||
|
||||
.diffusion-path-icon {
|
||||
display: block;
|
||||
padding-left: 28px;
|
||||
background-repeat: no-repeat;
|
||||
background-position: 1px 1px;
|
||||
height: 18px;
|
||||
padding-top: 1px;
|
||||
}
|
||||
|
||||
.diffusion-path-icon-ext {
|
||||
background-image: url(/rsrc/image/icon/fatcow/folder_go.png);
|
||||
}
|
||||
|
||||
.diffusion-path-icon-dir {
|
||||
background-image: url(/rsrc/image/icon/fatcow/folder.png);
|
||||
}
|
||||
|
||||
.diffusion-path-icon-file {
|
||||
background-image: url(/rsrc/image/icon/fatcow/page_white_text.png);
|
||||
}
|
||||
|
||||
.diffusion-path-icon-link {
|
||||
background-image: url(/rsrc/image/icon/fatcow/page_white_link.png);
|
||||
}
|
BIN
webroot/rsrc/image/icon/fatcow/folder.png
Executable file
BIN
webroot/rsrc/image/icon/fatcow/folder.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 632 B |
BIN
webroot/rsrc/image/icon/fatcow/folder_go.png
Executable file
BIN
webroot/rsrc/image/icon/fatcow/folder_go.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 803 B |
BIN
webroot/rsrc/image/icon/fatcow/page_white_link.png
Executable file
BIN
webroot/rsrc/image/icon/fatcow/page_white_link.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 732 B |
BIN
webroot/rsrc/image/icon/fatcow/page_white_text.png
Executable file
BIN
webroot/rsrc/image/icon/fatcow/page_white_text.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 568 B |
Loading…
Reference in a new issue