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
2012-03-21 22:01:20 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
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);
|
Use head_key() and last_key() to explicitly communicate intent
Summary:
PHP arrays have an internal "current position" marker. (I think because foreach() wasn't introduced until PHP 4 and there was no way to get rid of it by then?)
A few functions affect the position of the marker, like reset(), end(), each(), next(), and prev(). A few functions read the position of the marker, like each(), next(), prev(), current() and key().
For the most part, no one uses any of this because foreach() is vastly easier and more natural. However, we sometimes want to select the first or last key from an array. Since key() returns the key //at the current position//, and you can't guarantee that no one will introduce some next() calls somewhere, the right way to do this is reset() + key(). This is cumbesome, so we introduced head_key() and last_key() (like head() and last()) in D2161.
Switch all the reset()/end() + key() (or omitted reset() since I was feeling like taking risks + key()) calls to head_key() or last_key().
Test Plan: Verified most of these by visiting the affected pages.
Reviewers: btrahan, vrana, jungejason, Koolvin
Reviewed By: jungejason
CC: aran
Differential Revision: https://secure.phabricator.com/D2169
2012-04-09 20:08:59 +02:00
|
|
|
$best_match = head_key($matches);
|
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
2012-03-21 22:01:20 +01:00
|
|
|
|
|
|
|
if ($best_match) {
|
|
|
|
$repository = $repositories[$best_match];
|
|
|
|
$redirect = DiffusionRequest::generateDiffusionURI(
|
|
|
|
array(
|
|
|
|
'action' => 'browse',
|
|
|
|
'callsign' => $repository->getCallsign(),
|
2012-09-18 01:49:55 +02:00
|
|
|
'branch' => $repository->getDefaultBranch(),
|
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
2012-03-21 22:01:20 +01:00
|
|
|
'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) {
|
2013-02-07 01:53:49 +01:00
|
|
|
$desc = $uri.', at ';
|
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
2012-03-21 22:01:20 +01:00
|
|
|
}
|
2013-02-07 01:53:49 +01:00
|
|
|
$desc .= $id;
|
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
2012-03-21 22:01:20 +01:00
|
|
|
|
|
|
|
$content = id(new AphrontErrorView())
|
2013-05-11 17:23:19 +02:00
|
|
|
->setTitle(pht('Unknown External'))
|
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
2012-03-21 22:01:20 +01:00
|
|
|
->setSeverity(AphrontErrorView::SEVERITY_WARNING)
|
2013-02-07 01:53:49 +01:00
|
|
|
->appendChild(phutil_tag(
|
|
|
|
'p',
|
|
|
|
array(),
|
2013-05-11 17:23:19 +02:00
|
|
|
pht("This external (%s) does not appear in any tracked ".
|
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
2012-03-21 22:01:20 +01:00
|
|
|
"repository. It may exist in an untracked repository that ".
|
2013-05-11 17:23:19 +02:00
|
|
|
"Diffusion does not know about.", $desc)));
|
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
2012-03-21 22:01:20 +01:00
|
|
|
} else if (count($commits) == 1) {
|
|
|
|
$commit = head($commits);
|
2012-09-18 01:49:55 +02:00
|
|
|
$repo = $repositories[$commit->getRepositoryID()];
|
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
2012-03-21 22:01:20 +01:00
|
|
|
$redirect = DiffusionRequest::generateDiffusionURI(
|
|
|
|
array(
|
|
|
|
'action' => 'browse',
|
2012-09-18 01:49:55 +02:00
|
|
|
'callsign' => $repo->getCallsign(),
|
|
|
|
'branch' => $repo->getDefaultBranch(),
|
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
2012-03-21 22:01:20 +01:00
|
|
|
'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(),
|
2012-09-18 01:49:55 +02:00
|
|
|
'branch' => $repo->getDefaultBranch(),
|
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
2012-03-21 22:01:20 +01:00
|
|
|
'commit' => $commit->getCommitIdentifier(),
|
|
|
|
));
|
|
|
|
$rows[] = array(
|
2013-01-18 03:43:35 +01:00
|
|
|
phutil_tag(
|
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
2012-03-21 22:01:20 +01:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $href,
|
|
|
|
),
|
2013-01-18 03:43:35 +01:00
|
|
|
'r'.$repo->getCallsign().$commit->getCommitIdentifier()),
|
2013-02-13 23:50:15 +01:00
|
|
|
$commit->loadCommitData()->getSummary(),
|
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
2012-03-21 22:01:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = new AphrontTableView($rows);
|
|
|
|
$table->setHeaders(
|
|
|
|
array(
|
2013-05-11 17:23:19 +02:00
|
|
|
pht('Commit'),
|
|
|
|
pht('Description'),
|
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
2012-03-21 22:01:20 +01:00
|
|
|
));
|
|
|
|
$table->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'pri',
|
|
|
|
'wide',
|
|
|
|
));
|
|
|
|
|
|
|
|
$content = new AphrontPanelView();
|
2013-05-11 17:23:19 +02:00
|
|
|
$content->setHeader(pht('Multiple Matching Commits'));
|
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
2012-03-21 22:01:20 +01:00
|
|
|
$content->setCaption(
|
2013-05-11 17:23:19 +02:00
|
|
|
pht('This external reference matches multiple known commits.'));
|
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
2012-03-21 22:01:20 +01:00
|
|
|
$content->appendChild($table);
|
|
|
|
}
|
|
|
|
|
2013-05-11 17:23:19 +02:00
|
|
|
return $this->buildApplicationPage(
|
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
2012-03-21 22:01:20 +01:00
|
|
|
$content,
|
|
|
|
array(
|
2013-05-11 17:23:19 +02:00
|
|
|
'title' => pht('Unresolvable External'),
|
|
|
|
'device' => true,
|
|
|
|
'dust' => true,
|
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
2012-03-21 22:01:20 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|